MySQL - MINUTE() Function



The MySQL MINUTE() function is used to retrieve and return the minutes in the given time or date time expression. This returns a numerical value ranging from 0 to 59.

The MINUTE() function accepts the time string as an argument and retrieves the minutes part of it. Thus, the range of result always lies between 0 to 59.

Note that this function does not calculate the duration from the given time in the form of minutes, but just gets the minutes from the timestamp argument passed to it.

Syntax

Following is the syntax of MySQL MINUTE() function −

MINUTE(time);

Parameters

This method accepts the time expression from which you need to extract the minute as a parameter.

Return value

This function returns the minutes in the given time or date time expression.

Example

In the following example, we are using the MySQL MINUTE() function to extract the microsecond component from the given time value −

SELECT MINUTE('00:00:00 09:40:45.2300') As Result;

Output

This will produce the following result −

Result
40

Example

Following is another example of this function −

SELECT MINUTE('00 12:38:48') As Result;

Output

Following is the output −

Result
38

Example

We can also pass the date-time expression as an argument to this function −

SELECT MINUTE('2015-09-05 22:40:45.2300') As Result;

Output

This will produce the following result −

Result
40

Example

We can pass the result of the NOW() function as an argument to this function −

SELECT MINUTE(NOW()) As Result;

Output

Following is the output −

Result
53

In this example, we have created a table named SALES using the following CREATE TABLE query −

CREATE TABLE SALES(
   CUST_NAME varchar(255),
   PRODUCTNAME varchar(255),
   DISPATCHTIMESTAMP varchar(255),
   LOCATION varchar(255)
);

Now, insert the following records into the SALES table using the INSERT statement −

INSERT INTO SALES VALUES
('Aadhya', 'Key-Board', '2019-05-04 15:02:45.6542', 'Kerala'),
('Varun', 'Earphones', '2019-06-26 14:13:12.6321', 'Mumbai'),
('Vratha', 'Mouse', '2019-12-07 07:50:37.26112','Vijayawada'),
('Rahul', 'Mobile', '2018-03-21 16:00:45.261123', 'Chennai'),
('Maaya', 'Headset', '2018-12-30 10:49:27.21223', 'Goa');

Execute the below query to fetch all the inserted records in the above-created table −

Select * From SALES;

Following is the ORDERS table −

CUST_NAME PRODUCTNAME DISPATCHTIMESTAMP LOCATION
Aadhya Key-Board 2019-05-04 15:02:45.6542 Kerala
Varun Earphones 2019-06-26 14:13:12.6321 Mumbai
Vratha Mouse 2019-12-07 07:50:37.26112 Vijayawada
Rahul Mobile 2018-03-21 16:00:45.261123 Chennai
Maaya Headset 2018-12-30 10:49:27.21223 Goa

Now, we are using the MySQL MINUTE() function to retrieve the minute values from the "DispatchTimeStamp" column −

SELECT CUST_NAME, DISPATCHTIMESTAMP, MINUTE(DispatchTimeStamp)
As Minutes FROM SALES;

Output

The output is displayed as follows −

CUST_NAME DISPATCHTIMESTAMP Minutes
Aadhya 2019-05-04 15:02:45.6542 2
Varun 2019-06-26 14:13:12.6321 13
Vratha 2019-12-07 07:50:37.26112 50
Rahul 2018-03-21 16:00:45.261123 0
Maaya 2018-12-30 10:49:27.21223 49
Advertisements