MySQL TIMESTAMPADD() Function

In MySQL, the TIMESTAMPADD() function adds the specified interval to a datetime value and returns the result.

TIMESTAMPADD() Syntax

Here is the syntax of MySQL TIMESTAMPADD() function:

TIMESTAMPADD(unit, interval, datetime)

Parameters

unit
Required. The unit of time interval. Available values: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR.
interval
Optional. An integer value.
datetime
Optional. A datetime value or expression.

Return value

The MySQL TIMESTAMPADD() function adds the specified interval to a datetime value and returns the result.

The TIMESTAMPADD() function will return NULL if any parameter is NULL.

TIMESTAMPADD() Examples

Here are some examples of the TIMESTAMPADD() function.

Example 1

Add 1 week or 7 days to 2022-02-28:

SELECT
    TIMESTAMPADD(WEEK, 1, '2022-02-28'),
    TIMESTAMPADD(DAY, 7, '2022-02-28');
+-------------------------------------+------------------------------------+
| TIMESTAMPADD(WEEK, 1, '2022-02-28') | TIMESTAMPADD(DAY, 7, '2022-02-28') |
+-------------------------------------+------------------------------------+
| 2022-03-07                          | 2022-03-07                         |
+-------------------------------------+------------------------------------+

Example 2

Add 10 seconds to 2022-02-28.

SELECT TIMESTAMPADD(SECOND, 10, '2022-02-28');
+----------------------------------------+
| TIMESTAMPADD(SECOND, 10, '2022-02-28') |
+----------------------------------------+
| 2022-02-28 00:00:10                    |
+----------------------------------------+