SQL MINUTE() Function

SQL MINUTE() Function


The SQL MINUTE() is a function, and return or extract the minute portion of a given input time value.

The SQL MINUTE() function returns a integer number specifying a whole number between 0 and 59, inclusive, representing the minute of the MINUTEs.

The SQL MINUTE() function is supports only datetime or timestamp based table columns or fields.

It can be used in SELECT statement as well in where clause.


SQL MINUTE() Syntax

The below syntax is used to get minute of the MINUTE value (a integer number between 0 to 59, inclusive) from a given input datetime value.

For SQL SERVER / MY SQL / MS ACCESS


SELECT MINUTE('valid_datetime_value' or 'valid_timestamp_value');




SQL MINUTE() Example - Using Expression Or Formula

The following SQL SELECT statement will extract the minute of the MINUTE value from a given input datetime value. We use now() function to get the input date value.


SELECT 
NOW() AS 'Current Date and Time', 
MINUTE(NOW()) AS 'Minute Value';

The result of above query is:

Current Date and Time Minute Value
24-08-2012 19:37:30 37

Sample Database Table - BookOrder

BookID BookName OrderDate Qty DeliveryDate
1 Sql Server Interview Questions 12-09-2002 10:05:57 1 22-10-2002 19:04:13
2 SQL Success - Database Programming Proficiency 24-06-2002 19:29:31 10 27-07-2002 12:59:27
3 Troubleshooting SQL Server 17-08-1997 15:38:06 6 19-08-1997 22:59:39
4 Red Gate Guide to SQL Server 26-01-2010 11:34:30 9 28-02-2010 23:57:35




SQL MINUTE() Example - With Table Column

The following SQL SELECT statement display the column "OrderDate" and "DeliveryDate" from the "BookOrder" table. The MINUTE() function will extract the MINUTE value(a whole integer number from 1 to 60) from the column "OrderDate" and we will stored that value to a new column called "Order MINUTE" and "Delivery MINUTE".


SELECT 
OrderDate, MINUTE(OrderDate) As 'Order MINUTE', 
DeliveryDate, MINUTE(DeliveryDate) As 'Delivery MINUTE' 
FROM BookOrder;

The result of above query is:

OrderDate Order MINUTE DeliveryDate Delivery MINUTE
12-09-2002 10:05:57 5 22-10-2002 19:04:13 4
24-06-2002 19:29:31 29 27-07-2002 12:59:27 59
17-08-1997 15:38:06 38 19-08-1997 22:59:39 59
26-01-2010 11:34:30 34 28-02-2010 23:57:35 57