TIMESTAMPADD()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Adds the given number of units to the DATE
or DATETIME
argument and returns the result.
USAGE
TIMESTAMPADD(unit, count, timestamp)
Argument Name | Description |
---|---|
| The unit name keyword (not a string) |
| The number of units to add |
| The |
DETAILS
TIMESTAMPADD()
is a date-time function that returns the resulting timestamp from adding the interval given as an integer in the second argument in unit given in the first argument to the date, or datetime in the third argument.
The return value is a DATETIME
string formatted as either YYYY-MM-DD
or YYYY-MM-DD hh:mm:ss
depending on the data type of the input timestamp and the units being added.
A NULL
is returned if any argument is NULL
.
EXAMPLES
SELECT TIMESTAMPADD(MINUTE, 1, '2020-01-02');
+---------------------------------------+
| TIMESTAMPADD(MINUTE, 1, '2020-01-02') |
+---------------------------------------+
| 2020-01-02 00:01:00 |
+---------------------------------------+
SELECT TIMESTAMPADD(WEEK, 2, '2020-01-02');
+-------------------------------------+
| TIMESTAMPADD(WEEK, 2, '2020-01-02') |
+-------------------------------------+
| 2020-01-16 00:00:00 |
+-------------------------------------+
SELECT TIMESTAMPADD(MONTH, 3, '2020-01-02 00:00:00');
+-----------------------------------------------+
| TIMESTAMPADD(MONTH, 3, '2020-01-02 00:00:00') |
+-----------------------------------------------+
| 2020-04-02 00:00:00 |
+-----------------------------------------------+
SELECT TIMESTAMPADD(YEAR, 1, '2019-01-02');
+-------------------------------------+
| TIMESTAMPADD(YEAR, 1, '2019-01-02') |
+-------------------------------------+
| 2020-01-02 00:00:00 |
+-------------------------------------+