What is the format of the time you saved to the database?

Source: Internet
Author: User
I now use time () to get unixtimestamp in PHP. What do you use. What are the advantages of using other formats like datetime? I use PHP all now time()Unix timestamp.

What do you use.

In other formatsdatetimeWhat are the advantages?

Reply content:

I use PHP all nowtime()Unix timestamp.

What do you use.

In other formatsdatetimeWhat are the advantages?

TIMESTAMP

In mysql, only one TIMESTAMP is used in each table, and datetime is used in the remaining time fields.

I use the int type to save the unix timestamp.

Timestamp can be saved until January 1, 2038.
Datetime can be saved to 9999

Or not .. Consider yourself ...... -_-|

Datetime is used.

Mysql provides two similar data types:DATETIMEAndTIMESTAMP.

Like you, except for special behaviorsTIMESTAMPBecause it is betterDATETIMEIt saves more space.

MongoDB

ISODate(Accurate to milliseconds) or UNIX timestamp (more accurate)

PostgreSQL

timestamp with time zone

PS: My answer is written in rst format and converted to HTML, because markdown does not seem to supportDescriptive list.

Generally, you can view the actual usage of a field. For example, date or datetime. If you want to perform an operation or comparison in SQL, use int. If both are available, both are used, and the code is updated synchronously.

Save with unix timestamp. to display the time, use the date function to process it.

Datetime or smalldate sometimes use int type to represent the timestamp

The 11-bit int is used to save the timestamp.

datetimeThe advantage is that it is easy for humans to read and is not limited by the start and end ranges of unix timestamp.

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

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

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.