Skip to main content

Posts

Showing posts with the label datetime2

Entity Framework, Sql Server 2008 why you should use DateTime2

If you’re using Sql Server 2008 with Entity Framework and have a DateTime field you have no doubt come across this error when Inserting or Updating an Entity System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The problem here lies in the fact that the .NET DateTime.MinValue equals 0001-1-1 but the Sql Server DateTime only covers 1753-1-1 through 9999-12-31 The very simple solution is to use DateTime2 in Sql Server 2008 which covers 0001-1-1 through 9999-12-31. DateTime2 has also has some other benefits .