Hello, I am using a query to retrieve the date of a particular event. The date is stored as mm-dd-yyyy. Is there any method where i can retrieve the date as month_name,year?
For example for the date 05-01-2011,the query should return May,2011.
Look at the styles option of CONVERT
If you are storing the date in a datetime field, then use this
Otherwise if it is a string, convert it to a date first...
It goes without saying, though, that SQL isn't the best place to be formatting your output, and it should be handled by the presentation layer.
There'll be a few ways to do it. CONVERT allows you to format dates into various formats, but there isn't a style that's exactly what you want. So one way is:
answered Jun 09, 2011 at 03:32 AM
Since you're using DB2, here's what I think will work, with the reservation that I'm not a DB2 developer.
If you have your dates in column dt of table T1 in schema S1:
When you say the date is stored as mm-dd-yyyy, do you mean that it's stored as a varchar datatype? Otherwise it's stored as a datetime or date datatype and may be presented as for example mm-dd-yyyy.
Anyway, if you have it as a varchar, you can cast it to datetime, and from that get the Monthname and year:
Will produce June, 2011 as a result