ADDDATE
Sintassi:
ADDDATE(data, INTERVAL espr unità), ADDDATE(espr, giorni)
Spiegazione
Se invocata con il secondo argomento nella forma INTERVAL
, ADDDATE()
è sinonimo di DATE_ADD()
. La funzione complementare
SUBDATE()
è sinonimo di DATE_SUB()
. Per informazioni sull'argomento INTERVAL
unità, si veda la pagina
DATE_ADD()
.
Se invocata con il secondo argomento nella forma giorni, MariaDB lo considera un numero intero di giorni che devono essere aggiunti a espr.
Esempi:
MariaDB [(none)]> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY); +-----------------------------------------+ | DATE_ADD('2008-01-02', INTERVAL 31 DAY) | +-----------------------------------------+ | 2008-02-02 | +-----------------------------------------+ 1 row in set (0.00 sec) MariaDB [(none)]> SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY); +----------------------------------------+ | ADDDATE('2008-01-02', INTERVAL 31 DAY) | +----------------------------------------+ | 2008-02-02 | +----------------------------------------+ 1 row in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SELECT ADDDATE('2008-01-02', 31); +---------------------------+ | ADDDATE('2008-01-02', 31) | +---------------------------+ | 2008-02-02 | +---------------------------+ 1 row in set (0.00 sec) MariaDB [(none)]>
CREATE TABLE t1 (d DATETIME); INSERT INTO t1 VALUES ("2007-01-30 21:31:07"), ("1983-10-15 06:42:51"), ("2011-04-21 12:34:56"), ("2011-10-30 06:31:41"), ("2011-01-30 14:03:25"), ("2004-10-07 11:19:34");
MariaDB [test]> SELECT d, ADDDATE(d, 10) from t1; +---------------------+---------------------+ | d | ADDDATE(d, 10) | +---------------------+---------------------+ | 2007-01-30 21:31:07 | 2007-02-09 21:31:07 | | 1983-10-15 06:42:51 | 1983-10-25 06:42:51 | | 2011-04-21 12:34:56 | 2011-05-01 12:34:56 | | 2011-10-30 06:31:41 | 2011-11-09 06:31:41 | | 2011-01-30 14:03:25 | 2011-02-09 14:03:25 | | 2004-10-07 11:19:34 | 2004-10-17 11:19:34 | +---------------------+---------------------+ 6 rows in set (0.00 sec) MariaDB [test]> SELECT d, ADDDATE(d, INTERVAL 10 HOUR) from t1; +---------------------+------------------------------+ | d | ADDDATE(d, INTERVAL 10 HOUR) | +---------------------+------------------------------+ | 2007-01-30 21:31:07 | 2007-01-31 07:31:07 | | 1983-10-15 06:42:51 | 1983-10-15 16:42:51 | | 2011-04-21 12:34:56 | 2011-04-21 22:34:56 | | 2011-10-30 06:31:41 | 2011-10-30 16:31:41 | | 2011-01-30 14:03:25 | 2011-01-31 00:03:25 | | 2004-10-07 11:19:34 | 2004-10-07 21:19:34 | +---------------------+------------------------------+ 6 rows in set (0.00 sec)
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.