Extract using extract() method along with cast(). Following is the syntax −
select extract(minute from cast(yourColumnName as time)) as anyAliasName from yourTableName;
Let us create a table −
mysql> create table demo15 −> ( −> value time −> ); Query OK, 0 rows affected (2.11 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo15 values('10:30:45'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo15 values('06:34:55'); Query OK, 1 row affected (0.17 sec)
Display records from the table using select statement −
mysql> select *from demo15;
This will produce the following output −
+----------+ | value | +----------+ | 10:30:45 | | 06:34:55 | +----------+ 2 rows in set (0.00 sec)
Following is the query to extract minute from time −
mysql> select extract(minute from cast(value as time)) as Minute from demo15;
This will produce the following output −
+--------+ | Minute | +--------+ | 30 | | 34 | +--------+ 2 rows in set (0.00 sec)