- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert MySQL time from HH:MM:SS to HH:MM
To convert, use MySQL TIME_FORMAT(). Let us first create a −
mysql> create table DemoTable1419 -> ( -> ArrivalTime time -> ); Query OK, 0 rows affected (0.78 sec)
Insert some records in the table using insert command. Here, we have inserted time records −
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)
Display all records from the table using select −
mysql> select * from DemoTable1419;
This will produce the following output −
+-------------+ | ArrivalTime | +-------------+ | 12:30:45 | | 11:00:55 | | 09:59:34 | +-------------+ 3 rows in set (0.00 sec)
Following is the query to convert MySQL time from HH:MM:SS to HH:MM −
mysql> select ArrivalTime,time_format(ArrivalTime,'%H:%i') from DemoTable1419;
This will produce the following output −
+-------------+----------------------------------+ | 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)
Advertisements