Jump to: navigation, search

Mysql ADDDATE

From w3cyberlearnings

Contents

MySQL ADDDATE Function

This function is synonym for DATE_ADD() function.

Syntax ADDDATE

  • date: is the date string
  • INTERVAL: key word
  • expr: valid number
  • unit: DAY, MONTH, YEAR
ADDDATE(date, INTERVAL expr unit);

OR

ADDDATE(date, DAYS);

Format

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'

Example 1: add 3 days

mysql> SELECT ADDDATE('2012-04-21', INTERVAL 3 DAY);
+---------------------------------------+
| ADDDATE('2012-04-21', INTERVAL 3 DAY) |
+---------------------------------------+
| 2012-04-24                            |
+---------------------------------------+
1 row in set (0.00 sec)

Example 2: add 3 months

mysql> SELECT ADDDATE('2012-04-21', INTERVAL 3 MONTH);
+-----------------------------------------+
| ADDDATE('2012-04-21', INTERVAL 3 MONTH) |
+-----------------------------------------+
| 2012-07-21                              |
+-----------------------------------------+
1 row in set (0.00 sec)

Example 3: add 3 years

mysql> SELECT ADDDATE('2012-04-21', INTERVAL 3 YEAR);
+----------------------------------------+
| ADDDATE('2012-04-21', INTERVAL 3 YEAR) |
+----------------------------------------+
| 2015-04-21                             |
+----------------------------------------+
1 row in set (0.00 sec)

Example 4: add 60 days

mysql> SELECT ADDDATE('2012-04-21', 60);
+---------------------------+
| ADDDATE('2012-04-21', 60) |
+---------------------------+
| 2012-06-20                |
+---------------------------+
1 row in set (0.00 sec)

Related Links



Navigation
Web
SQL
MISC
References