Int efficiency is significantly higher when the query time is compared. Xiang Wen see http://www.jb51.net/article/29767.htm
However, when you are working on a project or directly viewing data in the database, it is obvious that the int value is big at first glance. For example, we want
To view the registration time of a user:
Select reg_time from t_xx_users where user_id = 1;
At this time, the return value is an int value and the specific time cannot be intuitively viewed. Therefore, the conversion of datetime and int is involved,
In addition, the date and time of php also involve the corresponding conversion. This document briefly summarizes the following:
(1) php
Int value:
Time (): returns the number of seconds from the Unix epoch (GMT 00:00:00, January 1, January 1, 1970) to the current time.
We can use strtotime () to obtain the number of seconds from January 1-20, 1970 to 2012: strtotime ('2017-2-10 ');
Date value:
String date (string format [, int timestamp])
For example, the current time can be returned directly by date (). Of course, we can specify its format: for example, date ('Y-m-d ', strtotime ('2014-2-10 '));
Time Operation:
Date ('Y-m-d h: I: s', strtotime ('+ 1 week '));
Date ('Y-m-d h: I: s', strtotime ('+ 5 hours '));
Date ('Y-m-d h: I: s', strtotime ('Next Monday ));
Date ('Y-m-d h: I: s', strtotime ('Last Sunday '));
Date ('Y-m-d h: I: s', strtotime ('+ 1 Day', 12313223 ));!! For details, see int strtotime (string time [, int now]).
(2) mysql:
Int-> datetime
Select from_unixtime (int_time) from table;
Datetime-> int;
Select unix_timestamp (date_time) from table;
Time Operation:
Select dayofweek ('1970-2-2 '); returns the day of the week.
Select dayofmonth ('1970-2-2 '); returns the day from January 1, 2012.
Select dayofyear ('1970-2-2 '); returns the day of the year.
Similar function: month () day () hour () week ()......
+ Date_add (date, interval 2 days) in a few days );
-Date_sub (date, interval 2 days) in a few days );
Time Format:
Date_format (date, format)
Select DATE_FORMAT ('2017-10-04 22:23:00 ',' % W % M % y ');
Other functions: TIME_TO_SEC () SEC_TO_TIME ()...