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 at 2 years ago * This page is subject to Site terms.

More from Kontext

local_offer mssql local_offer t-sql

visibility 23
thumb_up 0
access_time 8 months ago

This code snippet shows how to calculate time differences.

open_in_new Code snippets

local_offer mssql local_offer t-sql

visibility 26
thumb_up 0
access_time 8 months ago

JSON is commonly used in modern applications for data storage and transfers. Pretty much all programming languages provide APIs to parse JSON. 

open_in_new Code snippets

local_offer mssql local_offer t-sql

visibility 16
thumb_up 0
access_time 8 months ago

In Oracle database, you can select from dual table if you only want to return a one row result set. In many other databases, the query engine supports select directly from constant values without specifying a table name. 

open_in_new Code snippets

local_offer mssql local_offer t-sql

visibility 32
thumb_up 2
access_time 8 months ago

In different databases, the syntax of selecting top N records are slightly different. They may also differ from ISO standards.

open_in_new Code snippets

info About author

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward