如何验证MySQL查询的到期日期?
您可以NOW()
为此使用。以下是语法-
select * from yourTableName where yourColumnName> now();
让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, expiryDateOfMedicine datetime );
使用插入命令在表中插入记录-
mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-27 11:29:00'); mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-26 10:39:21'); mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-28 11:30:10'); mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-29 12:44:11');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+----+----------------------+ | Id | expiryDateOfMedicine | +----+----------------------+ | 1 | 2019-04-27 11:29:00 | | 2 | 2019-04-26 10:39:21 | | 3 | 2019-04-28 11:30:10 | | 4 | 2019-04-29 12:44:11 | +----+----------------------+ 4 rows in set (0.00 sec)
以下是用于验证MySQL查询的到期日期的查询-
mysql> select * from DemoTable where expiryDateOfMedicine > now();
这将产生以下输出-
+----+----------------------+ | Id | expiryDateOfMedicine | +----+----------------------+ | 3 | 2019-04-28 11:30:10 | | 4 | 2019-04-29 12:44:11 | +----+----------------------+ 2 rows in set (0.00 sec)