DATE_ADD() 函數向日期添加指定的時間間隔。
文法
DATE_ADD(date,INTERVAL expr type)date 參數是合法的日期運算式。expr 參數是您希望添加的時間間隔。
type 參數可以是下列值:
Type 值
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH
執行個體一
加天數
mysql教程> select DATE_ADD(curdate(), INTERVAL 1 DAY);
+-------------------------------------+
| DATE_ADD(curdate(), INTERVAL 1 DAY) |
+-------------------------------------+
| 2007-07-23 |
+-------------------------------------+
1 row in set (0.00 sec)
加分鐘
mysql>
mysql> select DATE_ADD(curdate(), INTERVAL 1 MINUTE);
+----------------------------------------+
| DATE_ADD(curdate(), INTERVAL 1 MINUTE) |
+----------------------------------------+
| 2007-07-22 00:01:00 |
+----------------------------------------+
1 row in set (0.00 sec)
mysql>
加年數
mysql>
mysql> select DATE_ADD(curdate(), INTERVAL 1 YEAR);
+--------------------------------------+
| DATE_ADD(curdate(), INTERVAL 1 YEAR) |
+--------------------------------------+
| 2008-07-22 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql>
加小時候
mysql>
mysql> select DATE_ADD(curdate(), INTERVAL 1 HOUR);
+--------------------------------------+
| DATE_ADD(curdate(), INTERVAL 1 HOUR) |
+--------------------------------------+
| 2007-07-22 01:00:00 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql>