- ⌂ Date & Time
- Functions
TIMEDIFF()
Return the difference between two time/timestamp values, formatted as HH:MM:SS followed by optional decimal and microseconds (if microseconds provided in either timestamp).
Prototype
integer TIMEDIFF(mixed $end, mixed $start)
Parameters
- end - A time ("HH:MM:SS") or timestamp ("YYYY-MM-DD HH:MM:SS"), optionally followed by a decimal and microseconds.
- start - A time ("HH:MM:SS") or timestamp ("YYYY-MM-DD HH:MM:SS"), optionally followed by a decimal and microseconds..
Return
The hours minutes and seconds between end and start in HH:MM:SS format, or NULL if there is an error, such as an invalid timestamp.
The result returned by TIMEDIFF() is limited to the range allowed for TIME values (maximum of 838:59:59). Alternatively, you can use either of the functions TIMESTAMPDIFF() and UNIX_TIMESTAMP() to return an integer.
Examples
The difference between the Last Modified time and current time in HH:MM:SS format (max 838:59:59).
SELECT OID, TIMEDIFF(NOW(), META(LastModified)) AS TimeSinceModified FROM User
Get the difference between the Last Modified time and current time in seconds (virtually no maximum).
SELECT OID, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(META(LastModified)) AS SecondsSinceModified FROM User