MySQL HOUR() Function
In MySQL, the HOUR()
function extracts and returns the hour portion of a time.
HOUR()
Syntax
Here is the syntax of MySQL HOUR()
function:
HOUR(time)
Parameters
time
- Required. A time or datetime expression.
Return value
The MySQL HOUR()
function extracts the hour part of a specified time or datetime and returns it as a number.
- If there is no hour part in
time
, theHOUR()
function will return0
. - Tf the argument is
NULL
, TheHOUR()
function will returnNULL
. - Since MySQL supports a maximum time of
838:59:59
, the maximum number returned theHOUR()
function is838
.
HOUR()
Examples
Here are some examples of the 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
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): NULL
Here:
HOUR('123:10:10')
returns123
,HOUR('1234:10:10')
returns838
. This is because the maximum time is838:59:59
.- Although
'2022-02-00'
and'2022-02-30
are incorrect times, theHOUR()
function still returns0
.