ID EN
Date and Time Functions

TIMESTAMPADD(unit,interval,datetime_expr)

MySQL 8.4

Adds the integer expression interval to the date or datetime expression datetime_expr. The unit for interval is given by the unit argument, which should be one of the following values: MICROSECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.

Syntax

MYSQL
SELECT TIMESTAMPADD(MINUTE, 1, '2003-01-02');
'2003-01-02 00:01:00'
SELECT TIMESTAMPADD(WEEK,1,'2003-01-02');
'2003-01-09'

Examples

Example

The unit value may be specified using one of keywords as shown, or with a prefix of SQL_TSI_. For example, DAY and SQL_TSI_DAY both are legal.

MYSQL
SELECT TIMESTAMPADD(MINUTE, 1, '2003-01-02');
'2003-01-02 00:01:00'
SELECT TIMESTAMPADD(WEEK,1,'2003-01-02');
'2003-01-09'
Example 2

This function returns NULL if interval or datetime_expr is NULL.

MYSQL
SELECT TIMESTAMPADD(MONTH, 1, DATE '2024-03-30') AS t1,
     >        TIMESTAMPADD(MONTH, 1, DATE '2024-03-31') AS t2;
+------------+------------+
| t1         | t2         |
+------------+------------+
| 2024-04-30 | 2024-04-30 |
+------------+------------+
1 row in set (0.00 sec)