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 formatsdatetime
What are the advantages?
Reply content:
I use PHP all nowtime()
Unix timestamp.
What do you use.
In other formatsdatetime
What 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:DATETIME
AndTIMESTAMP
.
Like you, except for special behaviorsTIMESTAMP
Because it is betterDATETIME
It 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.
datetime
The advantage is that it is easy for humans to read and is not limited by the start and end ranges of unix timestamp.
timestamp
The 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