MySQL 8.1
HOUR(time)Parameters
- timeTIME
- Time or datetime
Return value
An integer from 0 to 23; up to 838 for a TIME value; NULL if the value is not recognized
Examples
Hour from a date and time
MySQL 8.1
SELECT HOUR('2022-06-16 16:37:03');Departure hour of trips
MySQL 8.1
SELECT id,
town_from,
town_to,
HOUR(time_out) AS departure_hour
FROM Trip;More hours than a day
MySQL 8.1
SELECT HOUR('100:30:00') AS hours;Details
For a TIME value, such as a duration, the hours are not limited to a day: HOUR('100:30:00') returns 100. To get the hours within a day, take the remainder: HOUR(t) % 24.