Convert string to date in T-SQL / SQL Server

visibility 373 access_time 3 years ago languageEnglish timeline Stats
timeline Stats
Page index 0.34

This code snippet shows how to convert string to date.

In SQL Server, CAST and CONVERT functions can be used to convert string/varchar to date.

For CONVERT function, there are many style argument you can use. 

For the complete list of styles supported, please refer to the following official page:

CAST and CONVERT (Transact-SQL)

Code snippet

SELECT CAST('2017-10-15' AS DATE);
SELECT CAST('20171015' AS DATE);
SELECT CONVERT(DATE,'2017-10-15',121);
SELECT CONVERT(DATE,'15-10-2017',105);
SELECT CONVERT(DATE,'15 OCT 2017',113);
SELECT CONVERT(DATE,'20171015',112);
info Last modified by Raymond 3 years ago copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
Calculate time difference in T-SQL / SQL Server
visibility 111
thumb_up 0
access_time 3 years ago
Add user for Azure SQL Database
visibility 49
thumb_up 0
access_time 10 months ago