MySQL Hour function is a Date Function, which is used to return the Hour from the given time. This function returns value from 0 to 23. However, if the time is larger, function will return value greater than 23.
In this article, we will show you, How to use this Hour function to get the Hours from Time in MySQL from an expression with example.
MySQL Hour Syntax
The basic syntax of the Hour() Function in MySQL is as shown below:
HOUR(Time or DateTime expression);
MySQL Hour function Example
These examples helps you understand the use of hour function. Here, we are returning the hours from different times, and a DateTime expression.
SELECT HOUR('2019-01-12 03:12:33');
MySQL Hour Function Example 2
The following queries show you, what happens when we try to return the hours from string DateTime, invalid time or 0 time value.
SELECT HOUR(NOW() + 15);
Thank You for Visiting Our Blog