Quantcast
Channel: Answers for "conversion of char data type to a datetime data type resulted in out-of-range"
Viewing all articles
Browse latest Browse all 8

Answer by Magnus Ahlkvist

$
0
0

When working with dates as input from text, I always convert to the format 'YYYYMMDD hh:mm:ss.nnn', because that's a format that will always work regardless of regional settings.

If you have dates stored as 'YYYY-MM-DD', then you should convert to this to be totally sure it's interpreted correctly: left(dob,4)+substring(dob,6,2)+substring(dob,9,2) + ' 00:00:00.000'

If the value is stored in a string-column (like char, or varchar), you don't have to add any quotes.

Please note also that if you store 'YYYYMMDD' in a char(10)-column, it's stored as 'YYYYMMDD ' (two blanks in the end). I haven't tested, but I suspect that might also lead to problems when using implicit conversion.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images