从格式中提取时间的 MySQL 查询而不显示秒
为此,您可以使用 time_format()。我们首先创建一个表 -
mysql> create table DemoTable1326 -> ( -> Arrivaltime time -> ); Query OK, 0 rows affected (0.50 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1326 values('12:10:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1326 values('20:00:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1326 values('22:45:55'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1326 values('04:10:24'); Query OK, 1 row affected (0.11 sec)
使用 select 语句从表中显示所有记录 -
mysql> select * from DemoTable1326;
这将产生以下输出 -
+-------------+ | Arrivaltime | +-------------+ | 12:10:45 | | 20:00:00 | | 22:45:55 | | 04:10:24 | +-------------+ 4 rows in set (0.00 sec)
下面是用来提取不显示秒数时间的查询 -
mysql> select time_format(Arrivaltime,'%H:%i') from DemoTable1326;
这将产生以下输出 -
+----------------------------------+ | time_format(Arrivaltime,'%H:%i') | +----------------------------------+ | 12:10 | | 20:00 | | 22:45 | | 04:10 | +----------------------------------+ 4 rows in set (0.00 sec)
广告