date_add,adddate
功能
向日期添加指定的时间间隔。
语法
DATETIME DATE_ADD(DATETIME|DATE date,INTERVAL expr type)
参数说明
-
date
:必须是合法的日期表达式。可以是 DATETIME 或 DATE 类型。 -
expr
:需要添加的时 间间隔,支持的数据类型为 INT。 -
type
:时间间隔的单位,取值可以是 YEAR,QUARTER,MONTH,DAY,HOUR,MINUTE,SECOND,MILLISECOND (3.1.7 及以后),MICROSECOND (3.1.7 及以后)。
返回值说明
返回 DATETIME 类型的值。如果输入值为空或者格式不正确,返回 NULL。
示例
select date_add('2010-11-30 23:59:59', INTERVAL 2 DAY);
+-------------------------------------------------+
| date_add('2010-11-30 23:59:59', INTERVAL 2 DAY) |
+-------------------------------------------------+
| 2010-12-02 23:59:59 |
+-------------------------------------------------+
select date_add('2010-11-30', INTERVAL 2 DAY);
+----------------------------------------+
| date_add('2010-11-30', INTERVAL 2 DAY) |
+----------------------------------------+
| 2010-12-02 00:00:00 |
+----------------------------------------+
select date_add('2010-11-30 23:59:59', INTERVAL 2 QUARTER);
+-----------------------------------------------------+
| date_add('2010-11-30 23:59:59', INTERVAL 2 QUARTER) |
+-----------------------------------------------------+
| 2011-05-30 23:59:59 |
+-----------------------------------------------------+
select adddate('2023-10-31 23:59:59', INTERVAL 1 MILLISECOND);
+--------------------------------------------------------+
| adddate('2023-10-31 23:59:59', INTERVAL 1 MILLISECOND) |
+--------------------------------------------------------+
| 2023-10-31 23:59:59.001000 |
+--------------------------------------------------------+
select adddate('2023-10-31 23:59:59', INTERVAL 1 MICROSECOND);
+--------------------------------------------------------+
| adddate('2023-10-31 23:59:59', INTERVAL 1 MICROSECOND) |
+--------------------------------------------------------+
| 2023-10-31 23:59:59.000001 |
+--------------------------------------------------------+