Name

ADDDATE()

Synopsis

ADDDATE(date, INTERVAL value type)
ADDDATE(date, days)

This function adds the given interval of time to the date or time provided. This is a synonym for DATE_ADD(); see its definition later in this chapter for details and interval types. The second, simpler syntax is available as of version 4.1 of MySQL. This shorthand syntax does not work, though, with DATE_ADD(). Here is an example:

UPDATE seminars
SET seminar_date = ADDDATE(seminar_date, INTERVAL 1 MONTH)
WHERE seminar_date = '2007-12-01';

UPDATE seminars
SET seminar_date = ADDDATE(seminar_date, 7)
WHERE seminar_date = '2007-12-15';

The first SQL statement postpones a seminar that was scheduled for December 1, 2007 to a month later (January 1, 2008). The second statement postpones the seminar on December 15 to December 22, seven days later.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.