Convert string to date in T-SQL / SQL Server

Raymond Raymond event 2019-11-18 visibility 805
more_vert

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);
More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts