MINUTE
MINUTE is a SQL function that is used to obtain the minute component from a specified time or timestamp value. The returned value ranges from 0 to 59, representing the minute portion of the given time. This function can be useful in extracting and comparing the minute units of different time values within a database.
MINUTE(time);
- time: This is the time value from which the minute value will be extracted. The ‘time’ input should be in a format that MySQL can recognize as a valid time or datetime type value. The MINUTE() function will then return the minute component of that time value, ranging from 0 to 59.
Example
SELECT MINUTE('2022-03-30 14:25:45');
Output
25
Explanation
The MINUTE function in MySQL extracts the minute from a given time or datetime value. In the example, it extracts ‘25’ as the minute from ‘2022-03-30 14:25:45’.
MINUTE(timestamp TIMESTAMPTZ) RETURNS INT
- timestamp timestamptz: This parameter represents a timestamp with time zone. This timestamp value is the input from which the function will extract the minute.
- returns int: This parameter signifies the function’s return type. Upon completion, the MINUTE function will yield an integer representing the minute component of the provided timestamp.
Example
SELECT EXTRACT(MINUTE FROM TIMESTAMP '2022-02-22 20:30:00');
Output
30
Explanation
The EXTRACT(MINUTE FROM TIMESTAMP)
function returns the minute from the provided timestamp. In this example, it returned ‘30’ as the minute value from the timestamp ‘2022-02-22 20:30:00’.
MINUTE(date)
- date: The date is the expression which specifies the date that SQL Server uses to return the minute part. The expression can be an argument that allows a date type such as a datetime, date, datetime2, smalldatetime, datetimeoffset, or a character string in the format ‘YYYY-MM-DD HH
Example
SELECT MINUTE('2022-06-20T14:25:10') AS MinuteValue;
Output
MinuteValue-----------25
Explanation
The MINUTE
function in SQL is used to extract the minute from a given date-time value. In the above example, the function is extracting the minute ‘25’ from the provided date-time string ‘2022-06-20T14:25:10’.
MINUTE(date)
- date: The date or datetime expression from which the minute value is to be extracted. It’s a valid entry in the field, whether it’s a column or a string literal containing a date.
Example
SELECT MINUTE(TO_DATE('12:30:25', 'HH24:MI:SS')) FROM dual;
Output
30
Explanation
The MINUTE
function is used to extract the minute component from a given time. In the provided example, the input time string ‘12:30:25’ is converted into a date format ‘HH24:MI:SS’, and then the minute ‘30’ is extracted.
MINUTE(datetime)
- datetime: This is the input parameter to the MINUTE() function. It specifies the datetime value from which you want to extract the minute. This parameter needs to follow a recognizable datetime format.
Example
SELECT MINUTE('2021-12-24 14:30:00');
Output
30
Explanation
The MINUTE()
function in this example returns the minute from the given timestamp, which is ‘30’.