In MariaDB, MINUTE()
is a built-in date and time function that returns the minutes portion of a given time expression.
It accepts one argument, which is the time you want to extract the minutes from.
The minutes are returned as a number in the range 0
to 59
.
Syntax
The syntax goes like this:
MINUTE(time)
Where time
is the time expression to get the minutes from.
Example
Here’s an example:
SELECT MINUTE('10:30:45');
Result:
+--------------------+ | MINUTE('10:30:45') | +--------------------+ | 30 | +--------------------+
Datetime Values
It also works with datetime values:
SELECT MINUTE('2030-02-01 10:30:45');
Result:
+-------------------------------+ | MINUTE('2030-02-01 10:30:45') | +-------------------------------+ | 30 | +-------------------------------+
Current Date
We can pass NOW()
as the datetime argument to use the current time:
SELECT
NOW(),
MINUTE(NOW());
Result:
+---------------------+---------------+ | NOW() | MINUTE(NOW()) | +---------------------+---------------+ | 2021-05-16 13:30:50 | 30 | +---------------------+---------------+
Invalid Arguments
When passed an invalid time argument, MINUTE()
returns null
:
SELECT MINUTE('10:75:00');
Result:
+--------------------+ | MINUTE('10:75:00') | +--------------------+ | NULL | +--------------------+
Missing Argument
Calling MINUTE()
with the wrong number of arguments, or without passing any arguments, results in an error:
SELECT MINUTE();
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
And another example:
SELECT MINUTE('10:30:45', '06:30:45');
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' '06:30:45')' at line 1