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!
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!
FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.
Boost your productivity with FavScripts.com!