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

后端 未结 15 1511
隐瞒了意图╮
隐瞒了意图╮ 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 09:46

    The conversion in SQL server fails sometimes not because of the Date or Time formats used, It is Merely because you are trying to store wrong data that is not acceptable to the system.

    Example:

    Create Table MyTable (MyDate);

    Insert Into MyTable(MyDate) Values ('2015-02-29');

    The SQL server will throw the following error:

    Conversion failed when converting date and/or time from character string.

    The reason for this error is simply there is no such date (Feb-29) in Year (2015).

提交回复
热议问题