Format date with full month name?
Posted on 2004-07-30
I have the field 'MESSAGE_DATE' in a table that is a 'datetime' type, containing data like this:
I would like a SQL function that will format the date like this:
October 21, 2003
If I use:
SELECT CONVERT(varchar, message_date, 107) FROM my_table
I get the following:
Oct 21, 2003
However, I want the full month name. Is there an easy function for doing this, similar to MySQL:
SELECT DATE_FORMAT(message_date, '%M %e, %Y');
I have constructed the following, and it works, but it's a bit wordy and I'm wondering if there is a more concise way to format a date in the format I want:
SELECT DATENAME(month, message_date) + ' ' + CAST(DAY(message_date) AS varchar) + ', ' + CAST(YEAR(message_date) AS varchar) AS message_date FROM my_table
Ideas on how to make that shorter, if possible?