在 MySQL 中将 11 天添加到当前日期
我们首先创建一个表 -
mysql> create table DemoTable1994 ( ArrivalDate date ); Query OK, 0 rows affected (5.33 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1994 values('2019-12-18'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1994 values('2019-12-19'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable1994 values('2019-12-20'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable1994 values('2019-12-25'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1994 values('2018-12-20'); Query OK, 1 row affected (1.42 sec)
使用 select 语句显示表中的所有记录 -
mysql> select * from DemoTable1994;
这将产生以下输出 -
+-------------+ | ArrivalDate | +-------------+ | 2019-12-18 | | 2019-12-19 | | 2019-12-20 | | 2019-12-25 | | 2018-12-20 | +-------------+ 5 rows in set (0.00 sec)
以下是对当前日期添加 11 天的 MySQL 查询 -
mysql> select ArrivalDate,date_add(ArrivalDate,interval 11 Day) from DemoTable1994 where ArrivalDate=curdate();
这将产生以下输出 -
+-------------+---------------------------------------+ | ArrivalDate | date_add(ArrivalDate,interval 11 Day) | +-------------+---------------------------------------+ | 2019-12-20 | 2019-12-31 | +-------------+---------------------------------------+ 1 row in set (0.00 sec)
广告