What is the format of the time you stored in the database?

Source: Internet
Author: User
I'm using PHP all the time. time()Get the Unix timestamp.

What do you use.

What are the advantages of using a different format datetime ?

Reply content:

I am now using PHP time() to get the Unix timestamp.

What do you use.

What are the advantages of using a different format datetime ?

TIMESTAMP

MySQL uses only one TIMESTAMP per table, and the remaining Time fields use DateTime.

I'm using the int type to save the UNIX timestamp.

Timestamp can be saved to 2038
DateTime can be saved to 9999

Sentimental or not. At your own discretion ...-_-| | |

It's using DateTime.

MySQL provides two similar data types: DATETIME and TIMESTAMP .

Like you, in addition to special behavior, usually used TIMESTAMP , because it is DATETIME more space-saving than.

Mongodb

ISODate(accurate to milliseconds) or UNIX timestamp (higher precision)

PostgreSQL

timestamp with time zone

PS: My answer is to write it in RST format and then turn it into HTML, because Markdown does not seem to support a descriptive list .

In general, look at the actual use of the field. If it is for people to see, date or DateTime, if it is to be done in SQL or comparison, with an int. If both are available, both types are used, and the code is updated in a synchronized way

Use the Unix timestamp to save, to display the time, then use the DATE function to process it.

datetime or smalldate sometimes use int type to represent timestamps

11-bit int Save the timestamp, I always do.

datetime, the benefits are easy for human reading and are not limited by the start and end range of Unix timestamp.

timestamp, the advantage is that it is easy to calculate the time difference between two points and to save space and to a certain extent easy to index.

There is a performance problem, if it is MySQL, it is recommended to look: http://gpshumano.blogs.dri.pt/2009/07/06/ mysql-datetime-vs-timestamp-vs-int-performance-and-benchmarking-with-myisam/

It's always int.

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