Details determine the time storage (Datetime,timestamp,int) in the success or failure-mysql

Source: Internet
Author: User
Tags php programming

In MySQL storage time, we can use the DateTime format, timestamp format, can also be used in int format. So what should we think about when we design?

First of all, I think we should understand how these formats are, and then look at their differences so that we can think about when to use the right format.

The datetime format, by default, is "Yyyy-mm-dd HH:MM:SS", which represents 19 characters from 1000-01-01 00:00:00-9999-12-31 23:59:59.

The timestamp format is also ' Yyyy-mm-dd HH:MM:SS ', which differs from DateTime in that its year value range is 1970-2037.

The format of INT is the form of integers, it can control the number of bits, generally we set to 10 bits on it.

So when to use DateTime, when the format to be displayed is fixed, that is, the date of the month and minute, and so on, the way, timestamp, although the range of the datetime is small, but generally we think his range is big enough, In addition, it can be set to update the time, automatically modify the value, that is, when we modify the database, such as INSERT or UPDATE, this field when we set the


Then when the use of int, originally int should not be the time format, but we have a lot of programming practice found that we usually in PHP programming, often need to format display time, such as only display date, if the database is an int type of time, Then we can directly use the PHP built-in function date () to convert, very convenient, and for time comparison is also more easy, because it is an int type, you can compare the size of the time can be compared directly.

Details determine the time storage (Datetime,timestamp,int) in the success or failure-mysql

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: 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.