This tutorial explains how to use the MySQL HOUR function with syntax and examples.
The MySQL HOUR function returns the hour portion of a date value.
The syntax for the HOUR function in MySQL is:
HOUR( date_value )
The time or datetime value from which to extract the hour.
The HOUR function can be used in the following versions of MySQL:
Let's look at some MySQL HOUR function examples and explore how to use the HOUR function in MySQL.
For example:
mysql> SELECT HOUR('2014-01-28 07:47:18.000004');
Output: 7
mysql> SELECT HOUR('2014-01-28 15:21:05');
Output: 15
mysql> SELECT HOUR('12:13:06');
Output: 12
mysql> SELECT HOUR('838:59:59');
Output: 838
This last HOUR example would display the hour portion of the current system time (current system time is returned by the CURTIME function).
mysql> SELECT HOUR(CURTIME());