Convert string to date in T-SQL / SQL Server

access_time 2 years ago visibility44 comment 0

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 copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

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


Learn more arrow_forward

More from Kontext

local_offer SQL local_offer SQL Server local_offer t-sql local_offer teradata local_offer teradata-sql-query

visibility 41986
thumb_up 0
access_time 6 years ago

SELECT is one of the most commonly used statements. In this tutorial, I will cover the following items: Two of the principal query clauses—FROM and SELECT Data Types Built-in functions CASE expressions and variations like ISNULL and COALESCE. * The function names mentioned above are ...

local_offer teradata local_offer t-sql local_offer mssql local_offer SQL local_offer SQL Server local_offer teradata-sql-query

visibility 4251
thumb_up 0
access_time 6 years ago

For Teradata developers, if you have no SQL Server installed, please go to the following link to download the SQL Server 2014 Expression Edition. http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx It is easy to get started and free to use.

local_offer SSIS local_offer mssql

visibility 13104
thumb_up 0
access_time 7 years ago

SSIS (SQL Server Integration Service) provides a number of convenient tasks to enable data integration. Exporting data from database to Excel file is a common task in ETL (Extract, Transform, Load) projects. Constantly the users/customers may raise format request regarding the Excel extract. To ...

About column

Code snippets for various programming languages/frameworks.

rss_feed Subscribe RSS