MySQL中ADDDATE()函数的使用教程

时间:2021-10-06 09:01:41
复制代码 代码如下:
ADDDATE(date,INTERVAL expr unit), ADDDATE(expr,days)

 

当被调用的第二个参数的区间形式,ADDDATE()是DATE_ADD()的同义词。相关功能SUBDATE()是DATE_SUB()的代名词。对于区间上的单元参数的详细信息,请参阅DATE_ADD()的说明。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql> SELECT DATE_ADD('1998-01-02', INTERVAL 31 DAY);
+---------------------------------------------------------+
| DATE_ADD('1998-01-02', INTERVAL 31 DAY)         |
+---------------------------------------------------------+
| 1998-02-02                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql> SELECT ADDDATE('1998-01-02', INTERVAL 31 DAY);
+---------------------------------------------------------+
| ADDDATE('1998-01-02', INTERVAL 31 DAY)         |
+---------------------------------------------------------+
| 1998-02-02                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)

当被调用的第二个参数的形式,MySQL的把它作为一个整数天数添加到expr。

?
1
2
3
4
5
6
7
mysql> SELECT ADDDATE('1998-01-02', 31);
+---------------------------------------------------------+
| DATE_ADD('1998-01-02', INTERVAL 31 DAY)         |
+---------------------------------------------------------+
| 1998-02-02                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)