Conversion failed when converting date and/or time from character string while inserting datetime

后端 未结 15 1514
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 09:34

I was trying to create a table as follows,

create table table1(date1 datetime,date2 datetime);

First I tried inserting values as below,

15条回答
  •  不知归路
    2020-11-22 10:09

    Simple answer - 5 is Italian "yy" and 105 is Italian "yyyy". Therefore:

    SELECT convert(datetime,'21-02-12 6:10:00 PM',5)
    

    will work correctly, but

    SELECT convert(datetime,'21-02-12 6:10:00 PM',105)
    

    will give error.

    Likewise,

    SELECT convert(datetime,'21-02-2012 6:10:00 PM',5)
    

    will give error, where as

    SELECT convert(datetime,'21-02-2012 6:10:00 PM',105)
    

    will work.

提交回复
热议问题