Date Conversions

Sybase and Microsoft's SQL Server can insert dates into a table in various formats; they can also extract dates in several different types of formats. This section shows you how to use SQL Server's CONVERT command to manipulate the way a date is displayed.

CONVERT (datatype [(length)], expression, format)

The following date formats are available with SQL Server when using the CONVERT function:

Format CodeFormat Picture
100mon dd yyyy hh:miAM/PM
101mm/dd/yy
102yy.mm.dd
103dd/mm/yy
104dd.mm.yy
105dd-mm-yy
106dd mon yy
107mon dd, yy
108hh:mi:ss
109mon dd, yyyy hh:mi:ss:mmmAM/PM
110mm-dd-yy
111yy/mm/dd
112yymmdd
						select "PayDate" = convert(char(15), paydate, 107)
						from payment_table
						where customer_id = 012845 PayDate --------------- May 1, 97 ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.