让我们首先创建一个表-
mysql> create table DemoTable1448 -> ( -> StartDate date, -> EndDate date -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1448 values('2019-01-21','2019-03-22'); mysql> insert into DemoTable1448 values('2019-04-05','2019-10-10'); mysql> insert into DemoTable1448 values('2019-10-01','2019-10-29'); mysql> insert into DemoTable1448 values('2018-12-31','2019-12-31');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1448;
这将产生以下输出-
+------------+------------+ | StartDate | EndDate | +------------+------------+ | 2019-01-21 | 2019-03-22 | | 2019-04-05 | 2019-10-10 | | 2019-10-01 | 2019-10-29 | | 2018-12-31 | 2019-12-31 | +------------+------------+ 4 rows in set (0.00 sec)
假设当前日期是-
2019-10-05
以下是查询以检查当前日期是否在给定的日期范围内-
mysql> select (curdate() >=StartDate and curdate() <=EndDate) as DateInRange from DemoTable1448;
这将产生以下输出-
+-------------+ | DateInRange | +-------------+ | 0 | | 1 | | 1 | | 1 | +-------------+ 4 rows in set (0.04 sec)