How to display only hour and minutes in MySQL?


To display only hour and minutes, use DATE_FORMAT() and set format specifiers as in the below syntax −

select date_format(yourColumnName,'%H:%i') as anyAliasName from yourTableName;

Let us first create a table −

mysql> create table DemoTable1527
   -> (
   -> ArrivalDatetime datetime
   -> );
Query OK, 0 rows affected (0.76 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1527 values('2019-01-10 12:34:45');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1527 values('2018-12-12 11:00:34');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1527 values('2019-03-21 04:55:56');
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1527;

This will produce the following output −

+---------------------+
| 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)

Following is the query to display only hour and minutes −

mysql> select date_format(ArrivalDatetime,'%H:%i') as HourAndMinutes from DemoTable1527;

This will produce the following output −

+----------------+
| HourAndMinutes |
+----------------+
| 12:34          |
| 11:00          |
| 04:55          |
+----------------+
3 rows in set (0.00 sec)

Updated on: 12-Dec-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements