Comparison Between. NET Framework datetime and SQL Server datetime

Source: Internet
Author: User
. 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 ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.