让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingDate datetime -> );
使用insert命令在表中插入一些记录。考虑当前日期“ 2019-06-28”-
mysql> insert into DemoTable(ShippingDate) values('2019-01-31'); mysql> insert into DemoTable(ShippingDate) values('2019-06-06'); mysql> insert into DemoTable(ShippingDate) values('2019-06-28'); mysql> insert into DemoTable(ShippingDate) values('2019-07-01');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 1 | 2019-01-31 00:00:00 | | 2 | 2019-06-06 00:00:00 | | 3 | 2019-06-28 00:00:00 | | 4 | 2019-07-01 00:00:00 | +----+---------------------+ 4 rows in set (0.00 sec)
这是NOW()
在MySQL中调用函数并从表中获取当前日期记录的查询-
mysql> select *from DemoTable where Date(ShippingDate)=Date(now());
输出结果
这将产生以下输出-
+----+---------------------+ | Id | ShippingDate | +----+---------------------+ | 3 | 2019-06-28 00:00:00 | +----+---------------------+ 1 row in set (0.00 sec)