totn MySQL Functions

MySQL: SUBTIME Function

This MySQL tutorial explains how to use the MySQL SUBTIME function with syntax and examples.

Description

The MySQL SUBTIME function returns a time/datetime value after which a certain time interval has been subtracted.

Syntax

The syntax for the SUBTIME function in MySQL is:

SUBTIME( start_value, time )

Parameters or Arguments

start_value
A time or datetime value to which the time interval should be subtracted.
time
The value of the time interval that you wish to subtract. It can be a positive or negative number.

Note

Applies To

The SUBTIME function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.1

Example

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');
Result: '2014-02-13 08:44:19.000001'

mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '3:2.000001');
Result: '2014-02-13 05:42:21.000001'

mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '4:3:2.000001');
Result: '2014-02-13 04:41:19.000001'

mysql> SELECT SUBTIME('2014-02-13 08:44:21.000002', '5 4:3:2.000001');
Result: '2014-02-08 04:41:19.000001'

mysql> SELECT SUBTIME('01:15:23.999998', '0.000001');
Result: '01:15:23.999997'

mysql> SELECT SUBTIME('01:15:23.999998', '5.000001');
Result: '01:15:18.999997'

mysql> SELECT SUBTIME('01:15:23.000001', '8:12:15.003441');
Result: '-06:56:52.003440'

mysql> SELECT SUBTIME('01:15:23.000001', '-8:12:15.003441');
Result: '09:27:38.003442'