Convert string to date in T-SQL / SQL Server

Raymond Tang Raymond Tang 863 0.39 index 6/2/2019

This code snippet shows how to convert string to date.

In SQL Server, CASTand CONVERTfunctions can be used to convert string/varchar to date.

For CONVERTfunction, 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);
mssql t-sql

Join the Discussion

View or add your thoughts below

Comments