萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql日期相加日期時間 DATE_ADD()函數

mysql日期相加日期時間 DATE_ADD()函數

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>

copyright © 萬盛學電腦網 all rights reserved