Converting Dates in SQL Server
In the world of Application and DB Development there is always a need to display dates in a format that is understandable to your audience. For example, in the US we normally expect to see a date as mm/dd/yyyy; however, in Great Britain, the normal format is dd/mm/yyyy. The Convert function in SQL Server provides a means to translate SQL Server’s default date format to just about any format.
The syntax for the Convert function is as follows:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
–
Available Date Formats –
Source Code
It shows some of the different ways dates can be formatted and produces the result below.
Below are a few resources that I found on using the Convert function.
- Working with SQL Server Date/Time Variables – DataBase Journal
- Working with SQL Server Date/Time Variables: Part Two – Displaying Dates and Times in Different Formats – DataBase Journal
- What the format codes mean in SQL ‘CONVERT’ – DBForums
- HOWTO – Compare a date string to datetime in SQL Server? – StackOverflow
- How to convert DateTime to VarChar – StackOverflow
- Sql Server string to date conversion – StackOverflow
I also posted a while back about Handling Dates in SQL Server.
–
Happy Learning!
Posted on January 18, 2009, in SQL Server. Bookmark the permalink. 1 Comment.







Pingback: SQL Server and Cloud Links for the Week | Brent Ozar - SQL Server DBA