

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 set time data type to be only HH:MM in MySQL?
You can use DATE_FORMAT() to set time data type to be only HH:MM.
Following is the syntax −
select DATE_FORMAT(yourColumnName, "%H:%i") AS anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( Arrivaltime time ); Query OK, 0 rows affected (0.61 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('08:20'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('05:40'); Query OK, 1 row affected (0.12 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | Arrivaltime | +-------------+ | 08:20:00 | | 05:40:00 | +-------------+ 2 rows in set (0.00 sec)
Here is the query to set only HH:MM in MySQL database −
mysql> select DATE_FORMAT(Arrivaltime, "%H:%i") AS ONLY_HOUR_MINUTE from DemoTable;
This will produce the following output −
+------------------+ | ONLY_HOUR_MINUTE | +------------------+ | 08:20 | | 05:40 | +------------------+ 2 rows in set (0.03 sec)
- Related Questions & Answers
- How to convert seconds to HH-MM-SS with JavaScript?
- How to use TIME type in MySQL?
- How to add time in a MySQL column set with type DATETIME?
- Changing data type from date to date/time in MySQL?
- How to convert MM/YY to YYYY-MM-DD in MYSQL?
- Which MySQL Data Type can be used to store Negative Number?
- How do I force the column alias to be of specific data type in MySQL?
- How to convert MM/YY to YYYY-MM-DD with a specific day in MySQL?
- How can Matplotlib be used to generate time-series data?
- How to set default date time as system date time in MySQL?
- How to fetch only N rows at a time in MySQL?
- How to compare DateTime Column with only Date not time in MySQL?
- How to insert mm/dd/yyyy format dates in MySQL?
- How to use time input type in HTML?
- Why we cannot use MySQL DATE data type along with time value?
Advertisements