MySQL查询要获取日期超过14天?
让我们首先创建一个-
mysql> create table DemoTable1392 -> ( -> ArrivalDate date -> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1392 values('2019-09-10'); mysql> insert into DemoTable1392 values('2019-09-26'); mysql> insert into DemoTable1392 values('2019-09-12'); mysql> insert into DemoTable1392 values('2018-09-20'); mysql> insert into DemoTable1392 values('2019-10-11');
使用选择显示表中的所有记录-
mysql> select * from DemoTable1392;
这将产生以下输出-
+-------------+ | ArrivalDate | +-------------+ | 2019-09-10 | | 2019-09-26 | | 2019-09-12 | | 2018-09-20 | | 2019-10-11 | +-------------+ 5 rows in set (0.00 sec)
当前日期如下-
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-09-26 | +------------+ 1 row in set (0.00 sec)
这是要获取14天以上的日期的查询-
mysql> select * from DemoTable1392 -> where ArrivalDate > date_sub(curdate(), interval 14 day);
这将产生以下输出-
+-------------+ | ArrivalDate | +-------------+ | 2019-09-26 | | 2019-10-11 | +-------------+ 2 rows in set (0.03 sec)