TIMESTAMPADD
Adds the specified number of time units to a date.
MySQL 8.1
TIMESTAMPADD(unit, value, datetime)Parameters
- unitkeyword
- Interval unit
- Values:MICROSECONDSECONDMINUTEHOURDAYWEEKMONTHQUARTERYEAR
- valueINT
- Number of units, can be negative
- datetimeDATETIME
- Source date or datetime
Return value
A date if days or larger units are added to a date, otherwise a datetime; if the month has no such day, its last day is used
Examples
Three hours added to a date
MySQL 8.1
SELECT TIMESTAMPADD(HOUR, 3, '2022-12-05 10:37:22') AS shifted;A month added to January 31
MySQL 8.1
SELECT TIMESTAMPADD(MONTH, 1, '2024-01-31') AS next_month;Negative value
MySQL 8.1
SELECT TIMESTAMPADD(MINUTE, -90, '2022-12-05') AS shifted;Details
Unlike DATE_ADD, the unit is the first argument, and compound units such as HOUR_MINUTE are not supported.