This MySQL function returns the hour for a DATETIME or TIME column.


Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).



This function returns the hour for the time given. For columns containing the time of day (e.g., DATETIME), the range of results will be from 0 to 23. For TIME data type columns that contain data not restricted to day limits, this function may return values greater than 23.

SELECT appt_id, appointment, 
HOUR(appointment) AS 'Hour of Appointment'
FROM appointments
WHERE client_id = '3992'
AND appointment > CURDATE( );

| appt_id | appointment         | Hour of Appointment |
| 8393    | 2008-03-15 13:00:00 |                  13 | 

This statement is selecting the upcoming appointment for a particular client. The hour is returned in military time (i.e., 13 is 1 p.m.).