将MySQL时间从HH:MM:SS转换为HH:MM
要进行转换,请使用MySQL TIME_FORMAT()。让我们首先创建一个-
mysql> create table DemoTable1419
-> (
-> ArrivalTime time
-> );
Query OK,0 rows affected(0.78秒)
使用insert命令将一些记录插入表中。这里,我们插入了时间记录-
mysql> insert into DemoTable1419 values('12:30:45');
Query OK,1 row affected(0.12 sec)
mysql> insert into DemoTable1419 values('11:00:55');
Query OK,1 row affected(0.45 sec)
mysql> insert into DemoTable1419 values('09:59:34');
Query OK,1 row affected(0.16 sec)
使用select显示表中的所有记录-
mysql> select * from DemoTable1419;
这将产生以下输出-
+-------------+
| ArrivalTime |
+-------------+
| 12:30:45 |
| 11:00:55 |
| 09:59:34 |
+-------------+
3 rows in set (0.00 sec)
以下是将MySQL时间从HH:MM:SS转换为HH:MM的查询-
mysql> select ArrivalTime,time_format(ArrivalTime,'%H:%i') from DemoTable1419;
这将产生以下输出-
+-------------+----------------------------------+
| ArrivalTime | time_format(ArrivalTime,'%H:%i') |
+-------------+----------------------------------+
| 12:30:45 | 12:30 |
| 11:00:55 | 11:00 |
| 09:59:34 | 09:59 |
+-------------+----------------------------------+
3 rows in set (0.05 sec)
阅读更多:MySQL 教程