sql server convert string to date yyyymmdd

Posted on : 24-04-2012 | By : Devi Prasad | In : SQL Server Basics


You can use cast or convert to convert string which is in yyyy/mm/dd (or) yyyy-mm-dd format to date.

Below is the script:
–yyyy/mm/dd using cast
SELECT CAST(‘2000/12/30’ AS DATE)
–yyyy-mm-dd using cast
SELECT CAST(‘2000-12-30′ AS DATE)

–yyyy/mm/dd using cast
SELECT CONVERT(date,’2000/12/30′)
–yyyy-mm-dd using cast
SELECT CONVERT(date,’2000-12-30’)

Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.

Your Ad Here

Tags: , ,