How do I convert dd/mm/yy into date datatype

Shilpa Praneesh picture Shilpa Praneesh · Dec 29, 2014 · Viewed 12.1k times · Source

I am able to convert the following to a varchar type

SELECT CONVERT(VARCHAR(11),'01/02/14',103)

I am getting an error while converting the above date to a date data type

SELECT Convert(date,'01/02/14',103)

I got the error saying

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

I also tried the following but didn't work.

SELECT Convert(date,CONVERT(VARCHAR(11),'01/02/14',103),103)

How can I convert to a date type?

Answer

user2941651 picture user2941651 · Dec 29, 2014

Please try this for dd/mm/yy format:

SELECT Convert(date,'01/02/14',3);

or this for dd/mm/yyyy format:

SELECT Convert(date,'01/02/2014',103);