在 MySQL 中从当天显示到当月剩下的日期记录?
首先,让我们创建一个表 -
mysql> create table DemoTable ( BookingDate date ); Query OK, 0 rows affected (0.67 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable values('2019-09-21'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2018-09-10'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-09-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-08'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2016-09-18'); Query OK, 1 row affected (0.17 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable;
将生成以下输出 -
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2018-09-10 | | 2019-09-10 | | 2019-09-08 | | 2016-09-18 | +-------------+ 5 rows in set (0.00 sec)
以下是 MySQL 中从当前日期到当月剩余日期的查询 -
mysql> select *from DemoTable where BookingDate between curdate() and last_day(curdate());
将生成以下输出 -
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2019-09-10 | | 2019-09-08 | +-------------+ 3 rows in set (0.01 sec)
广告