- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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)
- Related Articles
- MySQL query to get only the minutes from datetime?
- How to display only 200 characters from total value in MySQL?
- How to get hour, minutes and seconds in android using offset time API class?
- How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
- MySQL query to display only the empty and NULL values together?
- REGEX in MySQL to display only numbers separated by hyphen.
- GROUP BY and display only non-empty column values in MySQL
- MySQL query to compare and display only the rows with NULL values
- Only display row with highest ID in MySQL
- Display only a specific duplicate record in MySQL
- Display only date from timestamp value in MySQL
- Program to convert hour minutes’ time to text format in Python
- Implement MySQL IN for 2 columns to display only selected records
- Java Program to display hour and minute in AM or PM
- Find and display duplicate values only once from a column in MySQL

Advertisements