Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

SUBTIME

Example

Subtract 5.000001 seconds and return the resulting datetime.

SELECT SUBTIME(“2017-06-15 10:24:21.000004”“5.000001”);

Definition and Usage

The SUBTIME() function subtracts a specified time interval from a time or datetime expression and returns the resulting time or datetime.

Syntax

SUBTIME(datetimetime_interval)

Parameter Values

Parameter

Description

datetime

Required: The time or datetime to be adjusted

Time_interval

Required: The time interval to subtract from the datetime. Both positive and negative values are permitted.

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

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

SELECT SUBTIME(“2017-06-15 10:24:21.000004”“3:2:5.000001”);

Example

Subtract 5 seconds and return the resulting time.

SELECT SUBTIME(“10:24:21”“5”);

Example

Subtract 3 minutes from a time and return the resulting time.

SELECT SUBTIME(“10:24:21”“300”);

Example

Add 3 hours, 2 minutes, and 5 seconds to a time and return the resulting time.

SELECT SUBTIME(“10:24:21”“-3:2:5”);