Name

TIMEDIFF()

Synopsis

TIMEDIFF(time, time)

This function returns the time difference between the two times given. Although the arguments may be given in time or datetime format, both arguments must be of the same data type. Otherwise, NULL will be returned. Microseconds may be included in the values given. They will be returned when given and if the result is not zero microseconds. This function is available as of version 4.1.1 of MySQL. Here is an example:

SELECT appointment AS Appointment, 
NOW( ) AS 'Time Now',
TIMEDIFF(appointment, NOW( )) AS 'Time Remaining'
FROM appointments
WHERE rec_id='3783';

+--------------------+--------------------+----------------+
| Appointment        | Time Now           | Time Remaining |
+--------------------+--------------------+----------------+
| 2008-01-11 10:30:00| 2008-01-10 22:28:09| 12:01:51       |
+--------------------+--------------------+----------------+

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.