Converting a char data type to a date and time data type resulted in a date-time value out of range

I am working on importing data from excel server to sql. I am facing a problem while I am inserting date and date values ​​in sql server. He shows me this error:

[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 format on the excel sheet is in this format:

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

What do I need to do to import these two values ​​into the database?

+4
source share
1 answer

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

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

+4
source

All Articles