SQL – The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Error Message:

Msg 242, Level 16, State 3, Line 3
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Severity level:

16.

Description:

This error message appears, when SQL Server tries to convert a string to a DATETIME value and encounters that the resulting value is outside the valid range for DATETIME values.

Consequences:

The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:

Error of the Severity level 16 are generated by the user and are corrigible by the user.

Versions:
All versions of SQL Server.

Example(s):

DECLARE @dt VARCHAR(10)
SET @dt = ’17520101′
SELECT CAST(@dt AS DATETIME)

Remarks:

SQL Server offers a range of DATETIME values between 01/01/1753 and 12/31/9999. Values that are beyond this range cannot be stored in a column of the DATETIME type and any attempt raises this error.

SOURCE

LINK

LANGUAGE
ENGLISH