MariaDB HOUR() Function
In MariaDB, HOUR() is a built-in function that returns the hour part from a given time expression.
MariaDB HOUR() Syntax
This is the syntax of the MariaDB HOUR() function:
HOUR(time)
Parameters
time-
Required. A time or datetime expression.
Return value
The MariaDB HOUR() function extracts the hour portion of the specified time or datetime and returns it as a number.
If there is no hour part in time, the HOUR() function will return 0.
If the argument is NULL, the HOUR() function will return NULL.
Because the maximum time supported by MySQL is 838:59:59, the maximum return value of the HOUR() function is 838.
MariaDB HOUR() Examples
This statement shows the usage of the MariaDB HOUR() function:
SELECT
HOUR('10:10:10'),
HOUR('2022-02-28 10:10:10'),
HOUR('123:10:10'),
HOUR('1234:10:10'),
HOUR('2022-02-00'),
HOUR('2022-02-30'),
HOUR('Not A DATE'),
HOUR(NULL)\G
Output:
HOUR('10:10:10'): 10
HOUR('2022-02-28 10:10:10'): 10
HOUR('123:10:10'): 123
HOUR('1234:10:10'): 838
HOUR('2022-02-00'): 0
HOUR('2022-02-30'): 0
HOUR('Not A DATE'): NULL
HOUR(NULL): NULLIn this example:
HOUR('1234:10:10')returned 838, because 838 is the maximum time supported by MariaDB.- Both
HOUR('2022-02-00')andHOUR('2022-02-30')returned0. - If an illegal time expression or
NULLis provided, theHOUR()function will returnNULL.
Conclusion
In MariaDB, HOUR() is a built-in function that returns the hour part from a given time expression.