• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Converting Dates with SQL

I know I've done this before but can't remember

How do I convert a date so it comes out in long day, month year format in t-sql

for example



Monday, January 7, 2013
1 Solution
Kent DyerIT Security Analyst SeniorCommented:
CAST / CONVERT in BOL should cover this..



Steve WalesSenior Database AdministratorCommented:
Cast/Convert don't seem to translate the date format into words.

You need the DATENAME function to do that.

Here's a (somewhat ugly) way to handle it but shows how to extract the words from a datetime parameter:

select datename(dw,getdate())+', '+
       datename(mm,getdate())+' '+
       rtrim(convert(char,datepart(dd,getdate())))+', '+
       rtrim(convert(char,datepart(yyyy, getdate())))

Monday, January 7, 2013

Open in new window

DATEPART: http://msdn.microsoft.com/en-us/library/ms174420.aspx
DATENAME: http://msdn.microsoft.com/en-us/library/ms174395.aspx
take a look, contains all conversions

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Alpesh PatelAssistant ConsultantCommented:
select Format (sysdatetime(), 'D', 'en-US')
ValentinoVBI ConsultantCommented:
PatelAlpesh, the FORMAT function only exists in SQL Server 2012.  The question clearly states that the asker uses SQL Server 2008.  Please read the full question and other posts before deciding to post yourself. (this is not the first time)

The answer by sjwales achieves what has been asked.
Anthony PerkinsCommented:
this is not the first time
And unfortunately it will not be the last, despite repeated reminder over the years.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now