要在MySQL中添加两个星期的日期,请使用DATE_ADD()-
insert into yourTableName(yourColumnName) values(date_add(now(),interval 2 week));
让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime );
以下是获取当前日期的查询-
mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-02 10 :36 :49 | +-----------------------+ 1 row in set (0.00 sec)
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(ShippingDate) values(date_add(now(),interval 2 week));
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+-----------------------+ | Id | ShippingDate | +----+-----------------------+ | 1 | 2019-06-16 10 :37 :24 | +----+-----------------------+ 1 row in set (0.00 sec)