Solved

Format date with full month name?

Posted on 2004-07-30
1
3,611 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 69

Accepted Solution

by:
Scott Pletcher 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

623 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