How to use TIME type in MySQL?


Let us first create a table. Within that we have set a column with type TIME to get the login time −

mysql> create table DemoTable
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   LoginTime TIME NULL
);
Query OK, 0 rows affected (0.69 sec)

Insert records in the table using insert command −

mysql> insert into DemoTable(LoginTime) values('12:34:45');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(LoginTime) values('13:56:01');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable(LoginTime) values('04:12:23');
Query OK, 1 row affected (0.13 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 −

+----+-----------+
| Id | LoginTime |
+----+-----------+
| 1  | 12:34:45  |
| 2  | 13:56:01  |
| 3  | 04:12:23  |
+----+-----------+
3 rows in set (0.00 sec)

Updated on: 30-Jul-2019

157 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements