Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

ADDDATE

Example

Increase a date by 10 days and provide the resulting date.

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

Definition and Usage

The ADDDATE() function adds a time/date interval to a given date and subsequently returns the resulting date.

Syntax

ADDDATE(date, INTERVAL value addunit)

OR:

ADDDATE(datedays)

Parameter Values

Parameter

Description

date

Mandatory: The date for adjustment

days

Mandatory: The number of days to add to the date

value

Mandatory: The value of the time/date interval to be added. Both positive and negative values are accepted.

addunit

Mandatory: The type of interval to add. Options include:

  • 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 15 minutes to a given date and return the new date.

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

Example

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

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

Example

Subtract 2 months from a given date and return the new date.

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