TIMEDIFF
TIMEDIFF is an SQL function used to find the difference between two time or datetime expressions. The result is expressed as a time value.
TIMEDIFF(expr1, expr2)
- expr1: This parameter represents the first temporal value that will be used in the calculation. The value should be a valid time or datetime expression.
- expr2: This parameter signifies the second temporal value used in the calculation. It also requires a valid time or datetime expression.
Example
Output
Explanation
This MySQL function TIMEDIFF()
is used to get the difference between two TIME or DATETIME expressions. It is very useful when you want to calculate the difference between two times. The example calculates the difference between ‘15:30:00’ and ‘10:20:00’.
In this case, the difference is ‘05:10:00’ which is presented in the format of ‘HH:MM:SS’. The function provides the output in the time format no matter how many hours the difference covers.