Programmers learn & share
0 votes

Problem :

I am getting bellow error related to datetime
the conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
by (6.9k points)   | 29 views

1 Answer

0 votes

Solution :

  • I think both the DATETIME and DATETIME2 map to System.DateTime in .NET So you cannot really do a "conversion", as it is really the same .NET type.
  • Also please note that there are two different values for the "SqlDbType" for these two.
  • On SQL Server the date range supported is quite different.
  • DATETIME supports 1753/1/1 to 9999/12/31, while DATETIME2 supports 0001/1/1 through eternity.
  • So what you really need to do is check for the year of the date and if it is before 1753, you need to change it to after 1753 in order for the DATETIME column in SQL Server to handle it.
by (36.1k points)  
2,187 questions
2,514 answers
241 users