MySQL HOUR Function

MySQL Hour is one of the Date Functions, which returns the Hour from the given time. This Hour function returns the time value from 0 to 23. However, if the time is huge, this method returns a value greater than 23. The syntax of the Hour method is as shown below:

HOUR(Time or DateTime expression);

MySQL Hour function Example

These examples help you understand its use or its functionality of it. Here, we are returning the hours from different times and a DateTime expression.

SELECT HOUR('11:12:03');

SELECT HOUR('23:12:33');

SELECT HOUR('2019-01-12 03:12:33');
MySQL Get HOURS Example 1

Let us see another example of the Hour Date method. Here, we are using NOW, UTC_TIME, and UTC_TIMESTAMP inside this method to get the Hour from the current date and time.



HOUR Example 2

Hour Example 2

The following query shows you what happens when we try to return the hours from the string DateTime, invalid time, or 0 as the time value.


SELECT HOUR('10:12:87');

SELECT HOUR('00:00:00');
MySQL HOUR Function 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.