sql server convert string to date mm dd yyyy

Below script converts string(varchar) to date. Date value in string can be in the format mm/dd/yy (or) mm-dd-yyyy
SELECT CAST(’12/30/2000′ AS DATE)
–mm-dd-yyyy using cast
SELECT CAST(’12-30-2000′ AS DATE)

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

Leave a Reply

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