What is datetime2?

Glenn picture Glenn · Mar 17, 2009 · Viewed 26.1k times · Source

I´ve got this in a INSERT statment to MSSQL 2008

System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

Answer

Walden Leverich picture Walden Leverich · Mar 17, 2009

SQLServer's datetime datatype is a much smaller range of allowed values than .net datetime datatype. SQLServer's datetime type basically supports the gregorian calendar, so the smallest value you can have is 1/1/1753. In 2008 SQLServer added a datetime2 datatype that supports back to year 1 (there was no year 0). Sounds like you're trying to insert a datetime value that's before 1/1/1753 into a datetime (not datetime2) SQLServer column