MySQL中两个日期之间的差异

2021-11-20 00:00:00 datetime sql date mysql

如何计算两个日期的差值,格式为YYYY-MM-DD hh:mm:ss并以秒或毫秒为单位得到结果?

How to calculate the difference between two dates, in the format YYYY-MM-DD hh: mm: ss and to get the result in seconds or milliseconds?

推荐答案

SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');
-- result: 22:00:59, the difference in HH:MM:SS format


SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
-- result: 79259  the difference in seconds

因此,您可以将 TIMESTAMPDIFF 用于您的目的.

So, you can use TIMESTAMPDIFF for your purpose.

相关文章