Home  >  Article  >  Database  >  How to convert date to timestamp in mysql

How to convert date to timestamp in mysql

青灯夜游
青灯夜游Original
2021-12-02 16:59:5326144browse

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.

How to convert date to timestamp in mysql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn