MySQL ADDDATE() 函数


ADDDATE()函数用于将一个时间值增加到一个日期当中;通俗的讲,就是可以通过这个函数将一个日期增加多少天;

日期类型可以是DATEDATETIMETIMESTAMP

有两种调用形式;

ADDDATE(date,INTERVAL expr unit)

第二个参数是一个时间间隔表达式(点击了解时间间隔表达式):

mysql> SELECT ADDDATE('2021-05-30',INTERVAL 1 DAY);
+--------------------------------------+
| ADDDATE('2021-05-30',INTERVAL 1 DAY) |
+--------------------------------------+
| 2021-05-31                           |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT ADDDATE('2021-05-30',INTERVAL 1 HOUR);
+---------------------------------------+
| ADDDATE('2021-05-30',INTERVAL 1 HOUR) |
+---------------------------------------+
| 2021-05-30 01:00:00                   |
+---------------------------------------+
1 row in set (0.00 sec)

ADDDATE(date,days)

第二个参数是要增加的天数;

将日期增加100天:

mysql> SELECT ADDDATE('2021-05-30',100);
+---------------------------+
| ADDDATE('2021-05-30',100) |
+---------------------------+
| 2021-09-07                |
+---------------------------+
1 row in set (0.00 sec)

如需转载,请注明出处;本文地址:https://www.perfcode.com/p/mysql-adddate-function.html