This tutorial explains how to use the MySQL TIMEDIFF function with syntax and examples.
The MySQL TIMEDIFF function returns the difference (expressed as a time value) between two time/datetime values.
The syntax for the TIMEDIFF function in MySQL is:
TIMEDIFF( time1, time2 )
The two time/datetime to calculate the difference between. The calculation is time1 - time2.
The TIMEDIFF function can be used in the following versions of MySQL:
Let's look at some MySQL TIMEDIFF function examples and explore how to use the TIMEDIFF function in MySQL.
For example:
mysql> SELECT TIMEDIFF('2014-02-17 12:10:08', '2014-02-17 12:10:07');
Output: '00:00:01'
mysql> SELECT TIMEDIFF('12:10:08', '12:10:07');
Output: '00:00:01'
mysql> SELECT TIMEDIFF('11:41:14', '12:10:08');
Output: '-00:28:54'
mysql> SELECT TIMEDIFF('2014-02-17 12:10:08', '2014-02-16 12:10:08');
Output: '24:00:00'
mysql> SELECT TIMEDIFF('2014-02-17 12:10:08', '12:10:08');
Output: NULL