Home > Database > Mysql Tutorial > body text

Difference between two timestamps in seconds in MySQL?

WBOY
Release: 2023-08-29 10:25:08
forward
1502 people have browsed it

Difference between two timestamps in seconds in MySQL?

Now let us see the following method to calculate the time difference (in seconds) between two timestamps.

method

The following is a query to calculate the difference between two timestamps.

mysql> SELECT TIMESTAMPDIFF(SECOND, '2018-10-17 11:51:55', '2018-10-17 11:51:58');
Copy after login

The following is the output in seconds.

+---------------------------------------------------------------------+
| TIMESTAMPDIFF(SECOND, '2018-10-17 11:51:55', '2018-10-17 11:51:58') |
+---------------------------------------------------------------------+
|                                                                   3 |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
Copy after login

Method 2

The following is a query to calculate the difference between two timestamps with the help of UNIX Timestamp.

mysql>  SELECT UNIX_TIMESTAMP('2018-10-17 11:57:50') - UNIX_TIMESTAMP('2018-10-17 11:57:45') as DifferenceInSeconds;
Copy after login

The following is the output in seconds.

+---------------------+
| DifferenceInSeconds |
+---------------------+
|                   5 |
+---------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of Difference between two timestamps in seconds in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!