Maximum Dates in SQL Server

Discussion in 'Databases' started by australian3, May 20, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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
     
  2. Before I get flamed. I had a typo in the post

    The ASP.Net DateTime function is

    DateTime.MaxValue

    Thanks
     
  3. dmitri

    dmitri DiscountASP.NET Staff

    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.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page