PDA

View Full Version : Maximum Dates in SQL Server


australian3
05-20-2010, 11:44 PM
Hi. I have encountered an issue with dates.

The DateTime.MaxDate in ASP.Net 2.0 returns a value 9999-21-31 23:59:59.

In our development and QA environments inserts and updates to the tables using this value work without an issue.

The same set of sql statements fail in the discountasp.net live database with an invalid datetime

However I have imported data from QA into live with this Max data and if you select the rows either into datagrid or in SQL server studio the system happily returns and displays a datetime of

9999-12-31 23:59:59.997

Has anyone else found this problem and knows why this happens?

Thanks

australian3
05-20-2010, 11:55 PM
Before I get flamed. I had a typo in the post

The ASP.Net DateTime function is

DateTime.MaxValue

Thanks

dmitri
05-21-2010, 09:38 AM
The problem can be due to conversion from DateTime to SqlDateTime and vice versa. The precision of DataTime is 100ns, but SqlDateTime's precision is only 3.33ms. The conversion back and forth can result is slight difference in time. I believe you are getting 9999-12-31 23:59:59.997 instead of 9999-12-31 23:59:59.999. This difference in 3ms can be a problem if you are comparing those two values. From human perspective 3ms is negligible, but the computer will return you the error that those two values are not equal, something like "MaxValue is not equal to MaxValue" which sounds strange.