Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

SUBDATE

Example

Subtract 10 days from a given date and return the resulting date.

SELECT SUBDATE(“2017-06-15”, INTERVAL 10 DAY);

Definition and Usage

The SUBDATE() function subtracts a specified time/date interval from a given date and returns the resulting date. 

Syntax

SUBDATE(date, INTERVAL value unit)

OR:

SUBDATE(datedays)

Parameter Values

Parameter

Description

date

Required: The initial/original date

days

Required: The number of days to subtract from the original date  

value

Required: The value of the time/date interval to subtract. Both positive and negative values are accepted.

unit

Required: The type of interval, which can be one of the following values:

  • MICROSECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • QUARTER
  • YEAR
  • SECOND_MICROSECOND
  • MINUTE_MICROSECOND
  • MINUTE_SECOND
  • HOUR_MICROSECOND
  • HOUR_SECOND
  • HOUR_MINUTE
  • DAY_MICROSECOND
  • DAY_SECOND
  • DAY_MINUTE
  • DAY_HOUR
  • YEAR_MONTH

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Subtract 15 minutes from a given date and return the resulting date.

SELECT SUBDATE(“2017-06-15 09:34:21”, INTERVAL 15 MINUTE);

Example

Subtract 3 hours from a given date and return the resulting date.

SELECT SUBDATE(“2017-06-15 09:34:21”, INTERVAL 3 HOUR);

Example

Add 2 months to a given date and return the resulting date.

SELECT SUBDATE(“2017-06-15”, INTERVAL –2 MONTH);