. Net datetime indicates that the time range is wider. It can be expressed from January 1, to January 1. The zero value time is the start time of the range, that is, January 1, January 1, 0001.
The datetime type of SQL Server can only represent the time from January 1, to January 1. The zero-value time is not the start time of the range, but January 1, January 1, 1900. The time value between January 1, January 1-19, 1753 and January 1, January 1, year 00 is expressed as a negative number.
Although SQL Server indicates that the time range is smaller, the time accuracy is much higher. The datetime Time Precision of SQL Server is 1/300 seconds, that is, 3.33 milliseconds. The Time Precision of. Net datetime is 1/10 seconds, that is, 100 milliseconds. Obviously, the Time Precision of SQL Server is 30 times higher than that of. net.
However, since 2.0, the. NET Framework has implemented local time and coordinated world time processing. This is undoubtedly a good news for applications that often require time zone conversion.
In terms of data structure, datetime of SQL Server is an 8-byte storage structure. The four bytes store the date value calculated by the number of days, and the other four bytes store the time value calculated by 1/300 seconds.
The. NET datetime is a struct value type, which is actually stored as a 64-bit unsigned integer and occupies 8 bytes of space. However, only 62 of them indicate the tick answer (ticks) of time, and the other two indicate the local time or world time. The so-called Number of tick answers does not directly distinguish between the date and time. The total number of tick answers received from on January 1, 100 is calculated every January 1, 0001 milliseconds. Therefore, the date and time retrieved from datetime are calculated. Of course, the internal implementation is only done using a simple integer addition and modulo operation.
Since datetime is a value type, implicit or explicit packing and unpacking operations may exist when the datetime value needs to be accessed as an object. This is also worth attention.
I believe that through such a comparison, we can better understand some basic types of insider information. In the future, our minds will be as clear as our eyes.
Leadzen (Shenzhen ).