sql server convert string to date yyyymmdd

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’)

Leave a Reply

Your email address will not be published. Required fields are marked *