.Net - Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

$0
=
$0
+
$0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

I am creating an object in C#, populating it with some data and then trying to save it into SQL Server table:

User someUser = new User() {
   UserName = "TestUser",
   CreateDate = DateTime.MinValue
};

I am getting the following error from MS SQL Server:

> Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

Please help! Thanks!

1 Answer - total earned - 0 BTC ($0 USD)

1
=
0
=
$0
Everyone, even non-registered users could send Bitcoin Tips to YOU if they are inspired by your answer!

You could use SqlDateTime.MinValue instead of DateTime.MinValue. For example:

DateTime rngMin = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;

DateTime rngMax = (DateTime)System.Data.SqlTypes.SqlDateTime.MaxValue;

It is a well known issue - the C# DateTime = 01/01/0001 does not fit into SQL Server datetime column

datetime
Date and time data from January 1, 1753 through December 31, 9999, to an accuracy of 
one three-hundredth of a second (equivalent to 3.33 milliseconds or 0.00333 seconds). 
Values are rounded to increments of .000, .003, or .007 seconds

Hope this helps!

SEND BITCOIN TIPS
0

Post Answer


Will Bitcoin Tipping become a new Internet Culture?


Please share our story! THANK YOU!