Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

DATE_ADD

Example

Add 10 days to a given date and return the resulting date.

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

Definition and Usage

The DATE_ADD() function adds a time or date interval to a given date and returns the resulting date.

Syntax

DATE_ADD(date, INTERVAL value addunit)

Parameter Values

Parameter

Description

date

Specify the date to be adjusted.

value

Specify the value of the time or date interval to be added. Both positive and negative values are accepted.

addunit

Specify the type of interval to be added. It 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

Add a duration of 15 minutes to a given date and return the resulting date.

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

Example

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

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

Example

Subtract a duration of 2 months from a given date and return the resulting date.

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