Page 1 of 1

case within select day, month functions

PostPosted: Mon Dec 15, 2014 11:18 pm
by k singh
hi

I am using day , month functions to get day and month from a timestamp column in select query.
i.e. select day(bb), month(bb) from aaa; (bb - columns name, aaa - table)
I am gettings correct results. if day is less than 10 is appears as a single digit. I want it to appear as double digits.
for ex. if day is 1 , I need "01" instead of "1".

I tried using case statement.
select month(bb), case when day(bb) < 10 then 0||day(bb) else day(bb) end as day from aaa;
but still I am not getting "01". day greater or equal than 10 are fine. its day from 0-9 have issues.

note : 0||day(bb) works fine if I use select month(bb),0||day(bb) from aaa; it concats 0 before every day.

any help on this one will be appreciated. or is there any other way to do it .

thanks and regards

Re: case within select day, month functions

PostPosted: Tue Dec 16, 2014 1:03 am
by k singh
I was able to find the solution using VARCHAR_FORMAT(bb,'yyyymmdd')

thanks a lot for your help