user3452212
user3452212

Reputation: 11

Conversion error when changing datetime field

When trying to update a datetime field I get the following message

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

SQL:

begin tran
update CCDocumentDCH 
set DocDate = '2013-10-28 12:17:00.000'
where DocNo = '1346815'

Upvotes: 1

Views: 66

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270713

If you are using SQL Server (which is just a guess), try doing an explicit conversion:

update CCDocumentDCH
    set DocDate = convert(datetime, '2013-10-28 12:17:00.000', 121)
    where DocNo = '1346815';

I do believe that there exist international formats that will interpret "XXXX-XX-XX" as "YYYY-DD-MM". An explicit conversion fixes this problem.

Upvotes: 2

Related Questions