Home > Database > Mysql Tutorial > How to convert date to timestamp in mysql

How to convert date to timestamp in mysql

青灯夜游
Release: 2021-12-02 17:01:05
Original
26191 people have browsed it

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)
Copy after login

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');
Copy after login

Result:

1545711900
Copy after login

2. Turn to ten Three

SELECT REPLACE(unix_timestamp(current_timestamp(3)),'.','');
Copy after login

Result:

1545711900021
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template