webCOMAND

DATE_ADD()

Add a positive or negative amount of time to a date or timestamp.

Prototype

mixed DATE_ADD(mixed $date, INTERVAL integer $amount UNIT)

Parameters

  • date - A date (YYYY-MM-DD) or timestamp (YYYY-MM-DD HH:MM:SS).
  • amount - A positive or negative number of UNITs to add to the date.
  • UNIT - One of the following keywords: 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

If a date is provided, the adjusted date string is returned.  If a timestamp is provided, the adjusted timestamp string is returned.  If there is an error, such as an invalid date, NULL is returned.

Example

SELECT OID, Date, DATE_ADD(Date, INTERVAL 30 DAY) AS DueDate FROM Invoice

Related

ADDDATE()