如何在MySQL Datetime中添加天数?
我们首先创建一个表格 -
mysql> create table DemoTable1871 ( ArrivalDate datetime ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1871 values('2019-12-19 7:45:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2018-11-10 12:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2019-01-31'); Query OK, 1 row affected (0.00 sec)
使用 select 语句从表中显示所有记录 -
mysql> select * from DemoTable1871;
这将产生以下输出 -
+---------------------+ | ArrivalDate | +---------------------+ | 2019-12-19 07:45:00 | | 2018-11-10 12:00:00 | | 2019-01-31 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
以下是添加天的查询 -
mysql> update DemoTable1871 set ArrivalDate=date_add(ArrivalDate, interval 6 day); Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查一下表格记录 -
mysql> select * from DemoTable1871;
这将产生以下输出 -
+---------------------+ | ArrivalDate | +---------------------+ | 2019-12-25 07:45:00 | | 2018-11-16 12:00:00 | | 2019-02-06 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
广告