Comparison of datetime and timestamp usage in MySQL

Source: Internet
Author: User


difference Contrast


Stores

TIMESTAMP

1.4-byte storage (time stamp value was stored in 4 bytes)

2. Value is saved in UTC (It stores the number of milliseconds)

3. Time zone conversion, storage time for the current time zone conversion, retrieval and then converted back to the current time zone.

Datetime

1.8 bytes Storage (8 bytes storage)

2. Actual format storage (Just stores what you have stored and retrieves the same thing for you which have.)

3. Time zone Independent (It has nothing to deal with the TIMEZONE and conversion.)


Summary

Same point

Can be used to represent time
are displayed as strings

Different points

As the name suggests, date represents only the ' yyyy-mm-dd ' form of dates, DateTime represents the date plus time in the form of ' Yyyy-mm-dd HH:mm:ss ', timestamp the same as the datetime display.
Date and DateTime can be expressed as ' 1000-01-01 ' to ' 9999-12-31 ', timestamp because of the 32-bit int type, can represent ' 1970-01-01 00:00:01 ' to ' 2038-01-19 03:14:07 UTC time.
MySQL converts the time to UTC when it stores the timestamp type and then reverts to the current time zone when it is read. If you store a value of timestamp type, and then modify the MySQL time zone, you will get the wrong time when you read the value again. This does not happen in date and DateTime. The
 
TIMESTAMP type provides automatic update functionality, and you only need to set its default value to Current_timestamp.
The datetime and timestamp are persisted to the second and the milliseconds are ignored except that date is persisted to the day.

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.