MySQL – Add Time Value (Intervals) To Date

MySQL DATE_ADD() function allow you to add a time value (Intervals) to the selected date.

MySQL ADDDATE() function is the synonym of DATE_ADD() function.

The following examples will return a date after adding 31 days with the specified date 2014-01-02.

Syntax – DATE_ADD() Function

DATE_ADD(date,INTERVAL expr unit);

Example:

mysql> SELECT DATE_ADD('2014-01-02', INTERVAL 31 DAY);

Output:

'2014-02-02'

Syntax – ADDDATE() Function

ADDDATE(date,INTERVAL expr unit), ADDDATE(expr,days);

Example-1:

mysql> SELECT ADDDATE('2014-01-02', INTERVAL 31 DAY);

Output:

'2014-02-02'

Example-2:

mysql> SELECT ADDDATE('2014-01-02', 31);

Output:

'2014-02-02'

Arguments

Name Description
date Date or datetime value
INTERVAL Keyword
expr An expression specifying the interval value
unit Keyword indicating the units

The following table shows the expected form of the expr argument for each unit value.

unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'

Leave a Reply

Your email address will not be published.

*