Support | Contact Us
Search:

Date Formatting in SQL Server

Share: More

I was doing some SQL coding today for the first time in a few months (I love the high level / strategic stuff but it sure is fun to get a chance to code again) and I needed to format a SQL date in a couple of different formats and, even with Google, it took a while for figure out:

  • The most basic of formats MM/DD/YYYY (I.e. 02/03/2010).  I used this to format it:
    • SELECT CONVERT(Varchar, GetDate(), 101)
  • I also needed Month, D, YYYY (I.e.February 3, 2010).  I used this to format it:
    • SELECT DATENAME(MONTH,GetDate()) + ' ' + DATENAME(DAY,GetDate()) + ', ' + DATENAME(YEAR, GetDate())

If there is a better way (and I am sure there is) let me know in the comments.  Until then use these as a quick guide.

Happy formatting!

Care to Comment?

© 2010 NimbleUser • 656 Kreag Rd. Pittsford, NY 14534 • 585.586.4750