Posted by: Rhonda | January 18, 2009

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

tsql

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.

I also posted a while back about Handling Dates in SQL Server.

Happy Learning!


Responses

  1. [...] Converting Dates in SQL Server – Rhonda Tipton explains the CONVERT syntax for T-SQL for folks who need to convert between different date formats like MM/DD/YYYY and DD/MM/YYYY. [...]


Leave a response

You must be logged in to post a comment.

Categories