I have a piece of code that tries to insert a date into a database using linq to sql.
rec.CreationDateTime =System.DateTime.Now;
This line throws the exception
" SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM"
I have read the different solutions suggested online. What i don't understand is how System.DateTime.Now
can be outside the range that would cause this exception.
System.DateTime.Now
is certainly far above anywhere near "1753". Likewise the year "9999" is quite some way ahead of 2015.
Can someone enlighten me on how to solve this problem?
DateTime
column that you're trying to insertNULL
into (or e.g. the result of an empty string being converted to aDateTime
). FInd thatDateTime
, fix it to have a proper value for SQL Server - done. Or change the SQL Server datatype toDATETIME2(3)
to avoid these issues altogether (SQL Server 2008 and newer)