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

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

select timestampdiff(year, "2017-12-25 19:15:16","2018-12-25 23:55:16") as year_diff;
+-----------+
| year_diff |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)

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

select timestampdiff(month, "2017-12-25 19:15:16","2018-12-25 23:55:16") as month_diff;
+------------+
| month_diff |
+------------+
|         12 |
+------------+
1 row in set (0.00 sec)

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

select timestampdiff(day, "2018-11-25 19:15:16","2018-12-25 23:55:16") as day_diff;
+----------+
| day_diff |
+----------+
|       30 |
+----------+
1 row in set (0.01 sec)

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)

猜你喜欢

转载自blog.csdn.net/lz6363/article/details/85253414