
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to convert seconds to HH-MM-SS with JavaScript?
- How to Convert Seconds to Time (hh mm ss) or Vice Versa in Excel?
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- How to convert MM/YY to YYYY-MM-DD with a specific day in MySQL?
- MySQL - Convert YYYY-MM-DD to UNIX timestamp
- Convert 1 m to mm.
- Convert MM/DD/YY to Unix timestamp in MySQL?
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- Convert dd/mm/yyyy string to Unix timestamp in MySQL?
- Display hour with SimpleDateFormat(“hh”) in Java
- How to convert date YYYYMMDD to YY-MM-DD in MySQL query?
- Convert into centimetres (in decimals):(a) \( 3 \mathrm{~mm} \)(b) \( 56 \mathrm{~mm} \)(c) \( 8 \mathrm{~cm} 4 \mathrm{~mm} \)
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- Express the following as cm using decimals.(a) 2 mm (b) 30 mm (c) 116 mm (d) 4 cm 2 mm (e) 162 mm(f) 83 mm
- Express as cm using decimals(a) 5 mm(b) 60 mm(c) 164 mm(d) 9 cm 8 mm(e) 93 mm

Advertisements