MySQL: Unix_timestamp (), Unix_timestamp (date)
If no parameters are invoked, a Unix timestamp (the number of seconds after the ' 1970-01-01 00:00:00 ' GMT) is returned as an unsigned integer. If you call Unix_timestamp () with date, it returns the value of the parameter as the number of seconds after the ' 1970-01-01 00:00:00 ' GMT. Date can be a date string, a DateTime string, a timestamp, or a number in the YYMMDD or YYYMMDD format of a local time.
Mysql> Select Unix_timestamp ();
-> 882226357
mysql> Select unix_timestamp (' 1997-10-04 22:23:00 ');
-> 875996580
When Unix_timestamp is used in the TIMESTAMP column, the function returns the internal timestamp value directly without any implied "string-to-unix-timestamp" conversion. If you pass an overflow date to Unix_timestamp (), it will return 0, but be aware that only the basic scope checks will be performed (the year from 1970 to 2037, the month from 01 to 12, and the date from 01 to 31).
Here we can use
From_unixtime (Unix_timestamp), From_unixtime (Unix_timestamp,format) to format a unix_timestamp () timestamp, which will return ' YYYY-MM-DD HH: The Unix_timestamp parameter of the Mm:ss ' or YYYYMMDDHHMMSS format value is expressed in the form of whether the function is used in a string or in a digital context.
If format is already given, the format of the result depends on the format string. The format can contain the same descriptor as the Date_format () function entry list.
Mysql> Select from_unixtime (875996580);
-> ' 1997-10-04 22:23:00 '
Mysql> Select From_unixtime (875996580) + 0;
-> 19971004222300
Mysql> Select From_unixtime (Unix_timestamp (),
-> '%Y%d%m%h:%i:%s%x ');
-> ' 2003 6th August 06:22:58 2003 '
In PHP: Time ()
Time--Returns the current Unix timestamp
Returns the number of seconds since the Unix era (GMT January 1, 1970 00:00:00) to the current time.
Literally they are the same, all returning the number of seconds since the Unix era to the current time.
The author has done a test on the same server and found that the results of the two returns are the same.
Use From_unixtime in MySQL (1156219870, '%y-%m-%d ')
and PHP with date ("y-m-d", 1156219870) The result is the same! The only thing that wouldn't be sure was that the reaction was faster. But I still tend to use the time () function in PHP!