THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL SUBTIME() Function

❮ MySQL Functions

Example

Subtract 5.000001 seconds and return the datetime:

SELECT SUBTIME("2017-06-15 10:24:21.000004", "5.000001");
Try it Yourself »

Definition and Usage

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

Syntax

SUBTIME(start_value, time)

Parameter Values

Parameter Description
start_value Required. The time or datetime to be modified
time Required. The value of the time interval that you wish to subtract from start_value. Can be a positive or negative number

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.1

More Examples

Example

Subtract 3 hours, 2 minutes, 5.000001 seconds and return the datetime:

SELECT SUBTIME("2017-06-15 10:24:21.000004", "3:2:5.000001");
Try it Yourself »

Example

Subtract 5 seconds and return the time:

SELECT SUBTIME("10:24:21", "5");
Try it Yourself »

Example

Add 3 hours, 2 minutes, and 5 seconds, and return the time:

SELECT SUBTIME("10:24:21", "-3:2:5");
Try it Yourself »

❮ MySQL Functions