In this article, we would like to show you how to calculate the difference between two datetimes in MySQL.
-- SELECT TIMEDIFF('to_time','from_time'); SELECT TIMEDIFF('YYYY-MM-DD HH:MM:SS','YYYY-MM-DD HH:MM:SS');
YYYY- four-digit year format, e.g.
MM- month number (counted from
DD- day number (from
31- depending on month),
HH- hour number (from
MM- minute number (from
SS- second number (from
In this example, we will calculate the difference between two datetimes using
SELECT TIMEDIFF('2021-01-09 09:00:00','2021-01-08 08:00:00') AS 'time difference';
If you only want to calculate the difference between days (dates), go to this article.