{"id":189,"date":"2012-05-02T10:08:48","date_gmt":"2012-05-02T10:08:48","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/05\/02\/the-conversion-of-a-varchar-data-type-to-a-datetime-data-type-resulted-in-an-out-of-range-value\/"},"modified":"2012-05-02T10:08:48","modified_gmt":"2012-05-02T10:08:48","slug":"the-conversion-of-a-varchar-data-type-to-a-datetime-data-type-resulted-in-an-out-of-range-value","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/05\/02\/the-conversion-of-a-varchar-data-type-to-a-datetime-data-type-resulted-in-an-out-of-range-value\/","title":{"rendered":"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."},"content":{"rendered":"
When you try to convert varchar datatype to datetime you would get this error when the value in varchar datatype does not represent the correct range of date.<\/p>\n
Example Queries:
\n[sql]
\nSELECT CAST( ‘2012-04-31’ AS DATETIME)
\n[\/sql]<\/p>\n
Result: Other Sample queries: [sql] [sql] [sql]
\n
\nMsg 242, Level 16, State 3, Line 1
\nThe conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
\n<\/font><\/p>\n
\n[sql]
\nSELECT CAST( ‘2012-04-30 24:00:00.000’ AS DATETIME)
\n[\/sql]<\/p>\n
\nSELECT CAST( ‘2012-04-30 00:60:00.000’ AS DATETIME)
\n[\/sql]<\/p>\n
\nSELECT CAST( ‘2012-04-30 00:00:60.000’ AS DATETIME)
\n[\/sql]<\/p>\n
\nSELECT CAST( ‘2012-04-30 24:00:00.000’ AS DATETIME)
\n[\/sql]<\/p>\n