Skip to content
Related Articles

Related Articles

Improve Article

HOUR() Function in MySQL

  • Last Updated : 27 Nov, 2020

HOUR() function :
This function in MySQL is used to return the hour part for a specified date. The range of hours value is from 0 to 838. For example, if the specified time is “09:12:23”, this function will return 09 hours.

Syntax :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

HOUR(datetime)

Parameter :
This method accepts a parameter which is illustrated below :

  • datetime – Specified datetime value to extract the hour from.

Returns :
It returns the hour part for a specified time or date time value.



Example-1 :
Getting the hour “9” from the specified date and time “2020-11-24 09:32:00”.

SELECT HOUR("2020-11-24 09:32:00");

Output :

9

Example-2 :
Getting the hour “6” from the specified time “06:12:23”.

SELECT HOUR("06:12:23");

Output :

6

Example-3 :
Getting the hour “838” from the specified time “838:12:5”.

SELECT HOUR("838:12:5");

Output :

838

Application :
This function is used to return the hour part for a specified date (from 0 to 838).

My Personal Notes arrow_drop_up
Recommended Articles
Page :