MySQL query to extract time in a format without seconds



For this, you can use time_format(). Let us first create a table −

mysql> create table DemoTable1326    -> (    -> Arrivaltime time    -> ); Query OK, 0 rows affected (0.50 sec)

Insert some records in the table using insert command −

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)

Display all records from the table using select statement −

mysql> select * from DemoTable1326;

This will produce the following output −

+-------------+ | Arrivaltime | +-------------+ | 12:10:45    | | 20:00:00    | | 22:45:55    | | 04:10:24    | +-------------+ 4 rows in set (0.00 sec)

Here is the query to extract time without seconds −

mysql> select time_format(Arrivaltime,'%H:%i') from DemoTable1326;

This will produce the following output −

+----------------------------------+ | time_format(Arrivaltime,'%H:%i') | +----------------------------------+ | 12:10                            | | 20:00                            | | 22:45                            | | 04:10                            | +----------------------------------+ 4 rows in set (0.00 sec)
Updated on: 2019-11-05T06:38:25+05:30

370 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements