位置:首頁 > 數據庫 > MySQL教學 > MySQL subdate()函數

MySQL subdate()函數

SUBDATE(date,INTERVAL expr unit) 和 SUBDATE(expr,days)

當第二個參數INTERVAL形式調用, SUBDATE() 是DATE_SUB()的同義詞,有關INTERVAL單位參數信息,請參閱DATE_ADD()的討論。

mysql> SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
+---------------------------------------------------------+
| DATE_SUB('1998-01-02', INTERVAL 31 DAY)                 |
+---------------------------------------------------------+
| 1997-12-02                                              |
+---------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT SUBDATE('1998-01-02', INTERVAL 31 DAY);
+---------------------------------------------------------+
| SUBDATE('1998-01-02', INTERVAL 31 DAY)                  |
+---------------------------------------------------------+
| 1997-12-02                                              |
+---------------------------------------------------------+
1 row in set (0.00 sec)