In mysql, you can use the unix_timestamp() function to convert the date into a timestamp, with the syntax "UNIX_TIMESTAMP(date)"; this function will change the "date" parameter value to "'1970-01-01 00 The number of seconds after ":00:00'GMT" is returned in the form of a timestamp.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
mysql converts date to timestamp
In mysql, you can use the unix_timestamp() function to convert date to timestamp.
Syntax:
UNIX_TIMESTAMP(date)
The unix_timestamp() function, if called without parameters, returns a UNIX timestamp of unsigned integer type ('1970-01-01 00:00 :00'Seconds after GMT).
If you use date to call UNIX_TIMESTAMP(), it will return the parameter value in the form of seconds after '1970-01-01 00:00:00' GMT.
Example:
1. Turn to ten--
select UNIX_TIMESTAMP('2018-12-25 12:25:00');
Result:
1545711900
2. Turn to ten Three
SELECT REPLACE(unix_timestamp(current_timestamp(3)),'.','');
Result:
1545711900021
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to convert date to timestamp in mysql. For more information, please follow other related articles on the PHP Chinese website!