Tuesday 17 July 2018

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


Watch this example on YouTube

 

To fix it replace
Select Convert(datetime, '06122018')

with

Select Convert(datetime, Right('06122018', 4) + Left('06122018', 2) +
  Substring('06122018', 3, 2))

1 comment:

  1. Hello
    can you explane what Right + left Substring are along with the number you use like 4,3,2

    ReplyDelete