How do I format a data in SQL to read like this: Monday, November, 23 2009
+1
A:
Assuming you are using MySQL,
DATE_FORMAT(field_name, '%W, %M, %d %Y')
prime_number
2009-11-25 04:22:43
+11
A:
The usual suspects:
For MySQL:
DATE_FORMAT(t.date_column, '%W, %M, %d %Y')
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))
For Oracle:
TO_CHAR(t.date_column, 'DAY, MONTH, DD YYYY')
OMG Ponies
2009-11-25 04:28:34
+1 for saying "The usual suspects"
tster
2009-11-25 07:18:08
What version of SQL Server does DATENAME have an underscore in it?
Scozzard
2009-11-25 07:35:00
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
2009-11-25 21:56:26
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
2009-11-25 22:11:04
@Scozzard, it's even nicer if upvoters edit the answer to fix it :)
Jeffrey Kemp
2010-09-06 08:36:12
+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
Scozzard
2009-11-25 04:29:47