SQL ADDDATE()函數
ADDDATE(date,INTERVAL expr unit), ADDDATE(expr,days)
當第二個參數INTERVAL形式調用,ADDDATE() 是DATE_ADD()的同義詞。 相關函數SUBDATE()是DATE_SUB()同義詞。 有關INTERVAL 參數信息,請參閱DATE_ADD()的討論。
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)
當第二個參數days 的形式調用時,MySQL將其視為整數天數添加到expr。
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)