TIMESTAMPADD( )

This MySQL function adds the given number of intervals of time to the given date or time.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

TIMESTAMPADD(interval, number, datetime)

Explanation

This function adds the given number of intervals of time to the given date or time. The intervals accepted are listed in the table below. 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.

Examples

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

In this example, an appointment is set to an hour later.

  • FRAC_SECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • QUARTER
  • YEAR