将char数据类型转换为datetime数据类型会导致一个超出范围的datetime值

时间:2021-09-03 16:45:02

i am working on importing data from excel to sql server. i am facing problem while i am inserting the date and datetime values in sql server. It is showing me this error:

我正在从excel导入数据到sql server。当我在sql server中插入日期和datetime值时,我遇到了问题。它向我展示了这个错误:

[System.Data.SqlClient.SqlException] = {"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.\r\nThe statement has been terminated."}

the date and date time format in excel sheet are in this format:

excel表格中的日期和日期时间格式如下:

  Date          DateTime
2011-04-26  2011-04-26 13:30

What do i have to to do to import these two values to database?

如何将这两个值导入数据库?

1 个解决方案

#1


4  

That format will fail if set dateformat dmy. Make sure you have set dateformat ymd or remove the - from the dates. yyyymmdd will always work.

如果设置dateformat dmy,该格式将失败。确保您已经设置了日期格式ymd或从日期中删除-。名称总是工作。

http://www.sommarskog.se/wishlist.html#YYYYMMDD

http://www.sommarskog.se/wishlist.html名称

#1


4  

That format will fail if set dateformat dmy. Make sure you have set dateformat ymd or remove the - from the dates. yyyymmdd will always work.

如果设置dateformat dmy,该格式将失败。确保您已经设置了日期格式ymd或从日期中删除-。名称总是工作。

http://www.sommarskog.se/wishlist.html#YYYYMMDD

http://www.sommarskog.se/wishlist.html名称