Differences between smalldatetime and datetime (for reference)

Source: Internet
Author: User

I learned this lesson and thought that the difference between smalldatetime and datetime is only in the time range:

The valid time range of smalldatetime is ~ 2079/6/6

The valid time range of datetime is 1753/1/1 ~ 9999/12/31

So I decided that smalldatetime would be used if the value does not have to be too far from the date range.

But I ignore the more important difference, that isSmalldatetime is accurate to minutes, while datetime is accurate to 3.33 milliseconds.

Therefore, when I saved the data in seconds after 00, I found that it was originally caused by smalldatetime. After I changed the data type to datetime, the data in seconds can be stored normally.

**************************************** **************************************** *********
In SQL Server, smalldatetime can only be accurate to minutes, while datatime can be precise to 3% seconds (3.33 milliseconds ).

Smalldatetime usage4The first two bytes store the base date (January 1, January 1, 1900)AfterThe number of days. The last two bytes are stored after midnightMinutes.

Datetime usage8The first four bytes store the base date (January 1, 1900)BeforeOrAfterThe number of days, the last four bytes are stored after midnightMilliseconds.

Since the precision of datetime is 3% seconds, this involves decimal places. It can be a colon or a decimal point before milliseconds. It indicates the meaning of the colon at the same time, and 11: 11: 11: 21 indicates021Milliseconds. The preceding 0 is omitted, while the decimal point indicates the mathematical decimal point, for example, 11:11:11. 21.210Milliseconds. The value is omitted from the following 0.

 

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.