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.