MySQL query to get only the minutes from datetime?


Let us first create a table −

mysql> create table DemoTable
   -> (
   -> ShippingDate datetime
   -> );
Query OK, 0 rows affected (0.52 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2019-01-10 10:04:45');
Query OK, 1 row affected (0.18 sec)

mysql> insert into DemoTable values('2019-06-11 05:45:00');
Query OK, 1 row affected (0.23 sec)

mysql> insert into DemoTable values('2019-06-12 07:00:55');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+---------------------+
| ShippingDate        |
+---------------------+
| 2019-01-10 10:04:45 |
| 2019-06-11 05:45:00 |
| 2019-06-12 07:00:55 |
+---------------------+
3 rows in set (0.00 sec)

Here is the query to get minutes in MySQL −

mysql> select minute(ShippingDate) as Minutes from DemoTable;

Output

+---------+
| Minutes |
+---------+
| 4       |
| 45      |
| 0       |
+---------+
3 rows in set (0.00 sec)

Updated on: 30-Jul-2019

179 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements