GeoGo GeoGo - 1 year ago 110
MySQL Question

Difference between two dates in MySQL

How to calculate the difference between two dates, in the format

YYYY-MM-DD hh: mm: ss
and to get the result value in seconds or milliseconds?

Answer Source
SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');
-- result: 22:00:59.

SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
-- result: 79259  the difference in seconds with the time.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download