在 MySQL 中显示当前日期前的 Timestamp
我们先创建一个表 -
mysql> create table DemoTable( ArrivalDate timestamp ); Query OK, 0 rows affected (1.96 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable values('2019-09-14 17:25:00'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('2019-09-13 17:25:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2016-09-01 17:20:10'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('2019-09-11 12:00:00'); Query OK, 1 row affected (0.16 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+---------------------+ | ArrivalDate | +---------------------+ | 2019-09-14 17:25:00 | | 2019-09-13 17:25:00 | | 2016-09-01 17:20:10 | | 2019-09-11 12:00:00 | +---------------------+ 4 rows in set (0.04 sec)
以下是显示当前日期之前 Timestamp 的查询 -
mysql> select *from DemoTable where ArrivalDate < now();
这将产生以下输出 -
+---------------------+ | ArrivalDate | +---------------------+ | 2019-09-13 17:25:00 | | 2016-09-01 17:20:10 | | 2019-09-11 12:00:00 | +---------------------+ 3 rows in set (0.07 sec)
广告