This tutorial explains how to use the MySQL SUBTIME function with syntax and examples.
The MySQL SUBTIME function returns a time/datetime value after which a certain time interval has been subtracted.
The syntax for the SUBTIME function in MySQL is:
SUBTIME( start_value, time )
A time or datetime value to which the time interval should be subtracted.
The value of the time interval that you wish to subtract. It can be a positive or negative number.
The SUBTIME function can be used in the following versions of MySQL:
Let's look at some MySQL SUBTIME function examples and explore how to use the SUBTIME function in MySQL.
For example:
mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '2.000001');
Output: '2014-02-13 08:44:19.000001'
mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '3:2.000001');
Output: '2014-02-13 05:42:21.000001'
mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '4:3:2.000001');
Output: '2014-02-13 04:41:19.000001'
mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '5 4:3:2.000001');
Output: '2014-02-08 04:41:19.000001'
mysql> SELECT SUBTIME('01:15:23.999998', '0.000001');
Output: '01:15:23.999997'
mysql> SELECT SUBTIME('01:15:23.999998', '5.000001');
Output: '01:15:18.999997'
mysql> SELECT SUBTIME('01:15:23.000001', '8:12:15.003441');
Output: '-06:56:52.003440'
mysql> SELECT SUBTIME('01:15:23.000001', '-8:12:15.003441');
Output: '09:27:38.003442'