TIMEDIFF( )

This MySQL function returns the time difference between the two times given.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

TIMEDIFF(time, time)

Explanation

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 datatype. 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.

Examples

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       |
+--------------------+--------------------+----------------+