
- 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
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)
- Related Articles
- Using Time datatype in MySQL without seconds?
- How to convert time seconds to h:m:s format in Python?
- MySQL query to convert timediff() to seconds?
- MySQL extract year from date format?
- MySQL query to return the entire date and time based on a string and format
- How to get (format) date and time from mill seconds in Java?
- MySQL query to extract last word from a field?
- MySQL query to extract first word from a field?
- How to convert US date format to MySQL format in INSERT query?
- How to calculate time based on seconds in MySQL?
- Remove seconds from time field in MySQL?
- Extract Numeric Date Value from Date Format in MySQL?
- MySQL query to convert height format to centimeters?
- Format Seconds in s format in Java
- How to sum time in MySQL by converting into seconds?

Advertisements