MariaDB: TIMEDIFF Function
This MariaDB tutorial explains how to use the MariaDB TIMEDIFF function with syntax and examples.
Description
The MariaDB TIMEDIFF function returns the difference (expressed as a time value) between two time/datetime values.
Syntax
The syntax for the TIMEDIFF function in MariaDB is:
TIMEDIFF( time1, time2 )
Parameters or Arguments
- time1 and time2
- The two time/datetime to calculate the difference between. The calculation is
time1 - time2
.
Note
- A time value can range from -838:59:59' to '838:59:59'.
- When using the TIMEDIFF function, both time1 and time2 must be both time values, or both datetime values. You can not have one be a time value and the other be a datetime value, or the TIMEDIFF function will return a NULL value.
Applies To
The TIMEDIFF function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB TIMEDIFF function examples and explore how to use the TIMEDIFF function in MariaDB.
For example:
SELECT TIMEDIFF('2014-11-16 12:10:08', '2014-11-16 12:10:07'); Result: '00:00:01' SELECT TIMEDIFF('12:10:08', '12:10:07'); Result: '00:00:01' SELECT TIMEDIFF('11:41:14', '12:10:08'); Result: '-00:28:54' SELECT TIMEDIFF('2014-11-16 12:10:08', '2014-11-15 12:10:08'); Result: '24:00:00' SELECT TIMEDIFF('2014-11-16 12:10:08', '12:10:08'); Result: NULL
Advertisements