MySQL HOUR() Function

MySQL HOUR() function; In this tutorial, i am going to show you MySQL HOUR() function with the help of examples.

MySQL HOUR() Function

MySQL Hour() Function is MySQL DateTime function which is responsible to fetch the hour part from the datetime value specified in the query.

Syntax of MySQL HOUR() Function

The basic syntax of MySQL HOUR() function is:

HOUR(time)

The time here is the value that you want to extract the hour from the given DateTime value.

Example 1 – MySQL HOUR() Function

Let’s take an first example using MySQL HOUR() function; as follows:

SELECT HOUR('11:40:30');

Output-1

+------------------+
| HOUR('11:40:30') |
+------------------+
|               11 |
+------------------+

Example 2 – MySQL HOUR() Function

Let’s take an second example using the mysql hour() function; as follows:

SELECT HOUR('280:40:28');

Output-2

+-------------------+
| HOUR('280:40:28') |
+-------------------+
|               280 |
+-------------------+

Example 3 – MySQL HOUR() Function

Let’s take an third example using hour() function; as follows:

SELECT HOUR('-310:35:27');

Output-3

+--------------------+
| HOUR('-310:35:27') |
+--------------------+
|                310 |
+--------------------+

Example 4 – MySQL HOUR() with Now() Function

Let’s take an exmaple using hour() with NOW() function; as follows:

SELECT HOUR(NOW());

Output-4

+--------------------+
| HOUR(NOW)          |
+--------------------+
|                16  |
+--------------------+ 

Conclusion

MySQL HOUR() Function tutorial, you have learned how to use MySQL HOUR() function.

Leave a Comment