Solved

Format date with full month name?

Posted on 2004-07-30
1
3,599 Views
Last Modified: 2008-01-09
I have the field 'MESSAGE_DATE' in a table that is a 'datetime' type, containing data like this:
10/21/2003

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?
0
Comment
Question by:hendridm
1 Comment
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 350 total points
ID: 11680677
Not directly, AFAIK; that is somewhat odd.  This is the shortest way I know of:

SELECT DATENAME(MONTH, message_date) + SUBSTRING(CONVERT(VARCHAR(30), message_date, 107), 4, 20)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now