Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net DateTime MaxValue is different once it is stored in database

When I store date property with value DateTime.MaxValue in database and retrieve it back, the stored value does not equal to DateTime.MaxValue. The tick properties are off. Why is this?

Using MS SQL, data type for date field is 'datetime'

enter image description here

like image 232
dev.e.loper Avatar asked May 25 '11 15:05

dev.e.loper


People also ask

What is DateTime maxvalue?

The default and the lowest value of a DateTime object is January 1, 0001 00:00:00 (midnight). The maximum value can be December 31, 9999 11:59:59 P.M. Use different constructors of the DateTime struct to assign an initial value to a DateTime object.

What is the value of DateTime MinValue in C#?

The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar. MinValue defines the date and time that is assigned to an uninitialized DateTime variable.

What is the max value for DateTime in SQL Server?

Remarks. The maximum valid date for a SqlDateTime structure is December 31, 9999.


1 Answers

Because SQL datetime has lower resolution.

The DateTime data type in MS SQL represents Date and time data from January 1, 1753, to December 31, 9999, with an accuracy of one three-hundredth second, or 3.33 milliseconds. Values are rounded to increments of .000, .003, or .007 milliseconds.

source

The DateTime value type in .Net represents dates and times from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) Time values are measured in 100-nanosecond units called ticks.

source

like image 141
fearofawhackplanet Avatar answered Sep 19 '22 03:09

fearofawhackplanet