views:

183

answers:

4
+1  Q: 

SQL Date Format

How do I format a data in SQL to read like this: Monday, November, 23 2009

A: 

Which provider are you using? In SQL Server, it would be w/CONVERT. See here.

micahtan
+1  A: 

Assuming you are using MySQL,

DATE_FORMAT(field_name, '%W, %M, %d %Y')

prime_number
+11  A: 

The usual suspects:

For MySQL:

DATE_FORMAT(t.date_column, '%W, %M, %d %Y')

DATE_FORMAT

For SQL Server:

DATENAME(dw, t.date_column) +', '+ DATENAME(mm, t.date_column) +', '+ CAST(DAY(t.date_column) AS VARCHAR(2)) +' '+ CAST(YEAR(t.date_column) AS VARCHAR(4))

DATENAME

For Oracle:

TO_CHAR(t.date_column, 'DAY, MONTH, DD YYYY')

TO_CHAR

OMG Ponies
+1 for saying "The usual suspects"
tster
What version of SQL Server does DATENAME have an underscore in it?
Scozzard
Word of advice - the SQL Server statement won't execute unless you cast the DAY and YEAR values as varchar, nvarchar etc. Upvoters should probably check an answer has correct syntax or can execute before voting - no offense to you OMG.
Scozzard
Gah, I keep getting caught by SQL Server's lack of implicit datatype conversion. No offense taken - I really appreciate you letting me know.
OMG Ponies
@Scozzard, it's even nicer if upvoters edit the answer to fix it :)
Jeffrey Kemp
+3  A: 

This is for SQL Server (T-SQL)

SELECT DATENAME(dw,GETDATE()) + ', ' + DATENAME(MM, GETDATE()) + ', ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4))

Just replace GETDATE() with the date variable

Learn more about DATENAME

Scozzard