要仅显示小时和分钟,请使用DATE_FORMAT()并按照以下语法设置格式说明符-select date_format(yourColumnName,'%H:%i') as anyAliasName from yourTableName;
让我们首先创建一个表-mysql> create table DemoTable1527
-> (
-> ArrivalDatetime datetime
-> );
使用插入命令在表中插入一些记录-mysql> insert into DemoTable1527 values('2019-01-10 12:34:45');
mysql> insert into DemoTable1527 values('2018-12-12 11:00:34');
mysql> insert into DemoTable1527 values('2019-03-21 04:55:56');
使用select语句显示表中的所有记录-mysql> select * from DemoTable1527;
这将产生以下输出-+---------------------+
| ArrivalDatetime |
+---------------------+
| 2019-01-10 12:34:45 |
| 2018-12-12 11:00:34 |
| 2019-03-21 04:55:56 |
+---------------------+
3 rows in set (0.00 sec)
以下是仅显示小时和分钟的查询-mysql> select date_format(ArrivalDatetime,'%H:%i') as HourAndMinutes from DemoTable1527;
这将产生以下输出-+----------------+
| HourAndMinutes |
+----------------+
| 12:34 |
| 11:00 |
| 04:55 |
+----------------+
3 rows in set (0.00 sec)