Collections:
TIMEDIFF() - Difference of Two Timestamps
How to calculate the difference between two timestamps using the TIMEDIFF() function?
✍: FYIcenter.com
TIMEDIFF(from_time, to_time) is a MySQL built-in function that
calculates the difference from one timestamp to another.
For example:
SELECT TIMEDIFF('2028-12-31 23:59:59', '2028-12-30 01:01:01.000002');
-- +---------------------------------------------------------------+
-- | TIMEDIFF('2028-12-31 23:59:59', '2028-12-30 01:01:01.000002') |
-- +---------------------------------------------------------------+
-- | 46:58:57.999998 |
-- +---------------------------------------------------------------+
SELECT TIMEDIFF('2028-12-31 23:59:59', '2029-01-01 01:01:01.000002');
-- +---------------------------------------------------------------+
-- | TIMEDIFF('2028-12-31 23:59:59', '2029-01-01 01:01:01.000002') |
-- +---------------------------------------------------------------+
-- | -01:01:02.000002 |
-- +---------------------------------------------------------------+
SELECT TIMEDIFF('2028-12-31 23:59:59', '2029-01-01 01:01:01.000002')-1;
-- +-----------------------------------------------------------------+
-- | TIMEDIFF('2028-12-31 23:59:59', '2029-01-01 01:01:01.000002')-1 |
-- +-----------------------------------------------------------------+
-- | -10103.000002 |
-- +-----------------------------------------------------------------+
SELECT TIMEDIFF('23:59:59', '01:01:01.000002');
-- +-----------------------------------------+
-- | TIMEDIFF('23:59:59', '01:01:01.000002') |
-- +-----------------------------------------+
-- | 22:58:57.999998 |
-- +-----------------------------------------+
Reference information of the TIMEDIFF() function:
TIMEDIFF(from_time, to_time): time Subtracts to_time from from_time and returns the difference as a time value. Arguments, return value and availability: from_time: Required. The timestamp to be subtracted from. to_time: Required. The timestamp to be subtracted. time: Return value. The difference as a time value. Available since MySQL 4.
Related MySQL functions:
⇒ TIMESTAMP() - Adding Time to Timestamp
2023-11-17, 1031🔥, 0💬
Popular Posts:
What are single-byte character string data types supported in SQL Server Transact-SQL? Single-byte c...
Where Is the Export Dump File Located in Oracle? If you are not specifying the dump directory and fi...
How To Look at the Current SQL*Plus System Settings in Oracle? If you want to see the current values...
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...