In this guide, we will explain how to use the MySQL HOUR function with syntax and examples.
Description
The MySQL HOUR function returns the hour portion of a date value.
Syntax
The syntax for the HOUR function in MySQL is:
HOUR( date_value )
Parameters or Arguments
date_value
The time or datetime value from which to extract the hour.
Note
- The HOUR function returns the hour (a number ranging from 0 to 838) given a date value.
- Since a time value can range from -838:59:59′ to ‘838:59:59’, the HOUR function can return values up to 838 (ie: higher than 23).
- See also the EXTRACT, YEAR, QUARTER, MONTH, WEEK, DAY, MINUTE, SECOND, and MICROSECOND functions.
Applies To
The HOUR function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some HOUR function examples and explore how to use the HOUR function.
For example:
mysql> SELECT HOUR('2014-01-28 07:47:18.000004'); Result: 7 mysql> SELECT HOUR('2014-01-28 15:21:05'); Result: 15 mysql> SELECT HOUR('12:13:06'); Result: 12 mysql> SELECT HOUR('838:59:59'); Result: 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());
Next Topic : Click Here
Pingback: MySQL: FROM_DAYS Function | Adglob Infosystem Pvt Ltd