mysql日期相加日期时间 DATE_ADD()函数

作者:袖梨 2022-11-14

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>

相关文章

精彩推荐