EN
MySQL - TIMEDIFF() function example
0 points
In this article, we would like to show you TIMEDIFF()
function example in MySQL.
Quick solution:
xxxxxxxxxx
1
-- SELECT TIMEDIFF('to_time','from_time');
2
SELECT TIMEDIFF('HH:MM:SS','HH:MM:SS');
or
xxxxxxxxxx
1
-- SELECT TIMEDIFF('to_time','from_time');
2
SELECT TIMEDIFF('YYYY-MM-DD HH:MM:SS','YYYY-MM-DD HH:MM:SS');
Where:
YYYY
- four-digit year format, e.g.2021
,MM
- month number (counted from01
to12
),DD
- day number (from01
to31
- depending on month),HH
- hour number (from00
to24
),MM
- minute number (from00
to59
),SS
- second number (from00
to59
).
TIMEDIFF()
function returns the difference between two time or datetime expressions.
In this example, we will calculate the difference between two times using TIMEDIFF()
function.
Query:
xxxxxxxxxx
1
SELECT TIMEDIFF('09:30:00','08:00:00') AS 'time difference';
Result:

In this example, we will calculate the difference between two datetimes using TIMEDIFF()
function.
Query:
xxxxxxxxxx
1
SELECT TIMEDIFF('2021-01-09 09:00:00','2021-01-08 08:00:00') AS 'time difference';
Result:
