MySQL ADDDATE() Function

In MySQL, the ADDDATE() function adds a date/time interval to a date or datetime value and returns the result.

ADDDATE() Syntax

Here is the syntax of MySQL ADDDATE() function:

ADDDATE(date, days)

or

ADDDATE(date, INTERVAL value unit)

Parameters

date
Required. A data or datetime value or expression.
days
Required. The number of days to add to date.
value
Required. A date/time interval. Both positive and negative numbers are allowed.
unit
Required. The unit of the data/time interval.

The unit of the data/time interval 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

Return value

The ADDDATE() function adds the specified date/time interval to the specified data or datetime value and returns the result. The result’s date type is determined by the parameters:

  • If date is a DATE value and unit is YEAR, MONTH or DAY, it returns a DATE value.
  • If date is a DATE value and unit is HOURS, MINUTES or SECONDS, it returns a DATETIME value.
  • If date is a DATETIME value, it returns a DATETIME value.
  • If date is a TIME value and unit is YEAR, MONTH or DAY, it returns a DATETIME value.
  • If date is a TIME value and the computation involves only the HOURS, MINUTES and SECONDS parts , it returns a TIME value. (MySQL 8.0.28 and later)
  • Otherwise it returns a string value.

ADDDATE() Examples

Here are some examples of the ADDDATE() function.

Example 1

SELECT
    ADDDATE('2020-06-10', 10),
    ADDDATE('2020-06-10', -10)\G
 ADDDATE('2020-06-10', 10): 2020-06-20
ADDDATE('2020-06-10', -10): 2020-05-31

Example 2

SELECT
    ADDDATE('2020-06-10', INTERVAL 10 DAY),
    ADDDATE('2020-06-10', INTERVAL 10 HOUR)\G
 ADDDATE('2020-06-10', INTERVAL 10 DAY): 2020-06-20
ADDDATE('2020-06-10', INTERVAL 10 HOUR): 2020-06-10 10:00:00

Example 3

SELECT
    ADDDATE('2020-06-10 10:00:00', INTERVAL 10 HOUR),
    ADDDATE('2020-06-10 10:00:00', INTERVAL 10 MINUTE)\G
  ADDDATE('2020-06-10 10:00:00', INTERVAL 10 HOUR): 2020-06-10 20:00:00
ADDDATE('2020-06-10 10:00:00', INTERVAL 10 MINUTE): 2020-06-10 10:10:00

Example 4

SELECT
    ADDDATE(CURDATE(), INTERVAL 10 HOUR),
    ADDDATE(NOW(), INTERVAL 10 MINUTE)\G
ADDDATE(CURDATE(), INTERVAL 10 HOUR): 2022-04-11 10:00:00
  ADDDATE(NOW(), INTERVAL 10 MINUTE): 2022-04-11 08:35:42

Here, we used the CURDATE() function to get the current date and used the NOW() function to get the current datetime.