Meir
Meir

Reputation: 1074

SQL Server error: The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value

I run into this error with my statement:

insert into messages ([from], [to], [message], Subject, status, senderID, 
                      PassengerID, Taxis, bags, passengers, dest, Comments, [when])
values(2, 81, '2', 'Bid', 1, 2, 
       2, 2, 2, 2, '2', '2', CONVERT(smalldatetime, '25.7.2016 13:01'))

I get this error:

The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.

When running the same statement on the console, it works perfectly fine!

Upvotes: 2

Views: 981

Answers (2)

Krishnraj Rana
Krishnraj Rana

Reputation: 6656

You need to specify an appropriate style parameter in Convert function like this -

Insert into messages ([from],[to],[message],Subject,status,senderID,PassengerID,Taxis,bags,passengers, dest, Comments,[when])
   values(2,81,'2','Bid',1,2,2,2,2,2,'2','2',CONVERT(smalldatetime, '25.7.2016 13:01', 104))

Upvotes: 1

Daniel Ch. Bloch
Daniel Ch. Bloch

Reputation: 49

This has to do with your server settings. Seems that your server waits for an US Date format (mm dd yyy) while you enter a european format (dd mm yyyy).

Upvotes: 1

Related Questions