T-SQL Tutorial

Msg 242 Level 16 - Conversion of a varchar data type to a datetime


On Transact SQL language the Msg 242 Level 16 - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. This means that the format date is incorrect.

Msg 242 Level 16 Example:

Create table

USE model;
GO
create table Test
(id int not null,
name varchar(500) not null,
entry_date datetime not null
);
GO

Invalid statement:

USE model;
GO
insert into test(id,name,entry_date)
values(1,'mssql','29-12-2017');
GO

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

Correct statement:

USE model;
GO
insert into test(id,name,entry_date)
values(1,'mssql',getdate());
insert into test(id,name,entry_date)
values(2,'sql server',sysdatetime());
GO

Other error messages: