猿问

MySQL中两个日期之间的差异

如何以格式计算两个日期之间的差YYYY-MM-DD hh: mm: ss并以秒或毫秒为单位获取结果?



月关宝盒
浏览 531回答 4
4回答

SMILET

SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');-- result: 22:00:59, the difference in HH:MM:SS formatSELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); -- result: 79259  the difference in seconds因此,您可以TIMESTAMPDIFF为您的目的使用。

慕斯王

使用DATEDIFF获取以天为单位的日期差SELECT DATEDIFF('2010-10-08 18:23:13', '2010-09-21 21:40:36') AS days;+------+| days |+------+|   17 |+------+

慕虎7371278

SELECT TIMESTAMPDIFF(HOUR,NOW(),'2013-05-15 10:23:23')   calculates difference in hour.(for days--> you have to define day replacing hourSELECT DATEDIFF('2012-2-2','2012-2-1')SELECT TO_DAYS ('2012-2-2')-TO_DAYS('2012-2-1')
随时随地看视频慕课网APP
我要回答