MariaDB TIMESTAMPADD() Function

In MariaDB, TIMESTAMPADD() is a built-in function that adds the specified time interval to a datetime value and returns the result.

MariaDB TIMESTAMPADD() Syntax

This is the syntax of the MariaDB TIMESTAMPADD() function:

TIMESTAMPADD(unit, interval, datetime)

Parameters

unit

Required. The unit of time interval, available values ​​are: MICROSECOND, SECOND, MINUTE, HOUR, DAY, , WEEK, MONTH, QUARTER, YEAR.

interval

Optional. An integer value representing the time interval.

datetime

Optional. A datetime value or expression.

Return value

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

If either argument is NULL, the TIMESTAMPADD() function will return NULL.

MariaDB TIMESTAMPADD() Examples

Here are some common examples of the MariaDB TIMESTAMPADD() function.

Example 1

Add 1 week or 7 days to 2023-01-12:

SELECT
    TIMESTAMPADD(WEEK, 1, '2023-01-12'),
    TIMESTAMPADD(DAY, 7, '2023-01-12')\G

Output:

TIMESTAMPADD(WEEK, 1, '2023-01-12'): 2023-01-19
 TIMESTAMPADD(DAY, 7, '2023-01-12'): 2023-01-19

Example 2

Add 10 seconds to 2023-01-12 10:10:10:

SELECT TIMESTAMPADD(SECOND, 10, '2023-01-12 10:10:10');

Output:

+-------------------------------------------------+
| TIMESTAMPADD(SECOND, 10, '2023-01-12 10:10:10') |
+-------------------------------------------------+
| 2023-01-12 10:10:20                             |
+-------------------------------------------------+

Conclusion

In MariaDB, TIMESTAMPADD() is a built-in function that adds the specified time interval to a datetime value and returns the result.