为此,请使用以下语法-
select * from yourTableName where yourColumnName < DATE_ADD(CURDATE(), INTERVAL 2 WEEK);
注意:当前日期如下-
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)
让我们首先创建一个表-
mysql> create table DemoTable1607 -> ( -> ShippingDate date -> ) -> ;
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1607 values('2019-10-20'); mysql> insert into DemoTable1607 values('2019-11-04'); mysql> insert into DemoTable1607 values('2019-10-05'); mysql> insert into DemoTable1607 values('2019-09-21');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1607;
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 2019-10-20 | | 2019-11-04 | | 2019-10-05 | | 2019-09-21 | +--------------+ 4 rows in set (0.00 sec)
这是获取日期在当前日期之前+ 2周之前的记录的查询-
mysql> select * from DemoTable1607 where ShippingDate <DATE_ADD(CURDATE(), INTERVAL 2 WEEK);
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 2019-10-20 | | 2019-10-05 | | 2019-09-21 | +--------------+ 3 rows in set (0.06 sec)