为此,您可以使用time_format()。让我们首先创建一个表-
mysql> create table DemoTable1326 -> ( -> Arrivaltime time -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1326 values('12:10:45'); mysql> insert into DemoTable1326 values('20:00:00'); mysql> insert into DemoTable1326 values('22:45:55'); mysql> insert into DemoTable1326 values('04:10:24');
使用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)