Name

TIMESTAMPADD()

Synopsis

TIMESTAMPADD(interval, number, datetime)

This function adds the given number of intervals of time to the given date or time. Intervals that are accepted by this function are: FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, and YEAR. For compatibility with other systems, you can add the SQL_TSI_ prefix to these interval names (e.g., SQL_TSI_YEAR for YEAR). This function is available as of version 5.0.0 of MySQL and is similar to DATE_ADD(), but the list of intervals accepted is not exactly the same. Here is an example:

UPDATE appointments
SET appointment = TIMESTAMPADD(HOUR, 1, appointment)
WHERE appt_id = '8930';

In this example, an appointment is set to an hour 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.