In this guide, we will explain 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 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
- Using the SUBTIME function with a negative time value as a parameter is equivalent to using the ADDTIME function.
- See also the DATE_ADD, DATE_SUB, ADDDATE, and SUBDATE functions.
Applies To
The SUBTIME function can be used in the following versions :
- 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 SUBTIME function examples and explore how to use the SUBTIME function.
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'
Next Topic : Click Here
Pingback: MySQL: SUBDATE Function | Adglob Infosystem Pvt Ltd