可否仅从 datetime 获取 MySQL 查询的分钟数?
我们先创建一个表 −
mysql> create table DemoTable -> ( -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.52 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('2019-01-10 10:04:45'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-06-11 05:45:00'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('2019-06-12 07:00:55'); Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
+---------------------+ | ShippingDate | +---------------------+ | 2019-01-10 10:04:45 | | 2019-06-11 05:45:00 | | 2019-06-12 07:00:55 | +---------------------+ 3 rows in set (0.00 sec)
这是在 MySQL 中获取分钟数的查询 −
mysql> select minute(ShippingDate) as Minutes from DemoTable;
输出
+---------+ | Minutes | +---------+ | 4 | | 45 | | 0 | +---------+ 3 rows in set (0.00 sec)
广告