The Wayback Machine - https://web.archive.org/web/20240623235557/https://www.geeksforgeeks.org/hour-function-in-mysql/
Open In App

HOUR() Function in MySQL

Last Updated : 27 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 :

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).


Similar Reads

MINUTE(), MICROSECOND() and HOUR() functions in MySQL
1. MINUTE() : The MySQL MINUTE() function is used for return the minute part of a datetime value. It can be between 0 to 59.When the datetime is passed in MINUTE() function then it will return the minute value . Syntax - MINUTE(datetime) Parameter - It take parameter a dateline value. Return - It returns a minute numeric value between 0 to 59. Exam
2 min read
Day() and Hour() Function in MS Access
1. Day() Function : Day() function returns the day of the month for a given date. In this function, it will take a date as a parameter and it will return the day of that date. The returned day will between 1 to 31. Syntax : Day(date) Example-1 : SELECT Day(#02/23/2020#); Output - 23 Example-2 : SELECT Day(#09/10/2010#); Output - 10 2. Hour() Functi
1 min read
HOUR() and FROM_DAYS() function in MariaDB
1. HOUR() Function : In MariaDB, the HOUR() function is used to return the hour portion of a date value. In this function, the first parameter will be date_value. This function will return HOUR part of the given date. Since a time value can be range from -838:59:59' to '838:59:59' so that this function can return values 0 to up to 838. Syntax : HOU
2 min read
MySQL | Common MySQL Queries
MySQL server is a open-source relational database management system which is a major support for web based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. Even all social networking websites mainly Facebook, Twitter, and Google depends on MySQL dat
9 min read
Functions in MySQL | Numeric, String and Date Time Functions in MySQL
MySQL functions are powerful tools that help in performing complex calculations and data manipulation with ease. The functions in MySQL can edit rows and tables, alter strings, and help you manage organized and easy-to-navigate databases. A function is a special type of predefined command set that performs some operation and returns a value. Functi
3 min read
MySQL | LEAD() and LAG() Function
The LEAD() and LAG() function in MySQL are used to get preceding and succeeding value of any row within its partition. These functions are termed as nonaggregate Window functions. The Window functions are those functions which perform operations for each row of the partition or window. These functions produce the result for each query row unlikely
3 min read
MySQL | LAST_DAY() Function
The LAST_DAY() function in MySQL can be used to know the last day of the month for a given date or a datetime. The LAST_DAY() function takes a date value as argument and returns the last day of month in that date. The date argument represents a valid date or datetime. Syntax: LAST_DAY( Date ); If the date or datetime value is invalid, the function
2 min read
CURRENT_TIME() function in MySQL
CURRENT_TIME() function in MySQL is used to check the current time. It returns the current time as a value in 'hh:mm:ss' or hhmmss format, depending on whether the function is used in string or numeric context. Syntax : CURRENT_TIME OR CURRENT_TIME(precision) Parameter : This method accepts one parameter. precision - It specifies the returned fract
2 min read
WEEKOFYEAR() Function in MySQL
WEEKOFYEAR() function in MySQL is used to find the week number for a given date. If the date is NULL, the WEEKOFYEAR function will return NULL. Otherwise, it returns the value of week which ranges between 1 to 53. Note: The WEEKOFYEAR() function considers the first week of the year to be the week that contains the first day of January. Also, the we
3 min read
EXP() Function in MySQL
EXP() function in MySQL is used to returns E raised to the power of a specified number. Here E(2.718281...) is the base of the natural logarithm. Syntax : EXP(X) Parameter : This method accepts one parameter as mentioned above in the syntax and described below : X – A specified number which will be used as a power of E. Returns : It returns E raise
2 min read
Article Tags :