欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL中l获取两个时间的小时、分钟、秒之差

程序员文章站 2022-05-29 23:45:17
...

MySQL中l获取两个时间的小时之差:

select timestampdiff(hour, "2018-12-25 19:15:16","2018-12-25 23:55:16") as hour_diff;

+-----------+
| hour_diff |
+-----------+
|         4 |
+-----------+
1 row in set (0.00 sec)

MySQL中l获取两个时间的分钟之差:

select timestampdiff(minute, "2018-12-25 19:15:16","2018-12-25 20:55:16") as minute_diff;
+-------------+
| minute_diff |
+-------------+
|         100 |
+-------------+
1 row in set (0.00 sec)

MySQL中l获取两个时间的秒之差:

select timestampdiff(second, "2018-12-25 19:15:16","2018-12-25 19:55:16") as second_diff;
+-------------+
| second_diff |
+-------------+
|        2400 |
+-------------+
1 row in set (0.01 sec)