MySQL Hour() FunctionLast Updated : 3 Feb 2026 The hour is a MySQL date/time function. It is used to get the hour from the given datetime. It returns an integer value ranging from 0 to 23. In this article, we will understand the concept of MySQL hour() function in detail with its various examples. SyntaxParameter:Datetime: datetime value for getting hour. Returns:This function returns the hour portion of a date value. Example 1Explanation: While executing the above query, the hour() function extracts the hours from the given date and time. Output: The result of the example is given below.
Example 2Explanation: While executing the above query, the hour() function extracts the hours from the given date and time. Output: The result of the example is given below.
Example 3:Explanation: While executing the above query, the hour() function extracts the hours from the current date and time. Output: The result of the example is given below.
Using MySQL DateTime hour function in a Table columnWe can use the MySQL DateTime hour() function in a table to extracts the hours from the given date/time and time table column. Following the steps below to perform the functionality of MySQL hour() function in a column of the table. Step 1: Create a table named Order_Details using the CREATE TABLE statement. Step 2: After that INSERT data into a table using the INSERT TABLE statement. Step 3: To check the information with the use of SELECT statement, whether the data is inserted or not.
Example:Explanation: While executing the above query, the hour() function is used to extract the time from a Order_Schduled column in the Order_Details table. Output: The result of the example is given below.
Using MySQL DateTime hour function in a Table with WHERE ClauseWe can use the MySQL DateTime hour() function in a table to return the hours from the table column. By using WHERE clause we can restrict the data. Sample Table: Order_Details
Example:Explanation: While executing the above query, the hour() function is used to extract the hour from a Order_Date column in the Order_Details table Where the value of the Amount column is greater than 600. Output: The result of the example is given below.
Using MySQL DateTime hour function with IN OperatorWe can use the MySQL datetime hour() function in a table to retrieve the hours from a table column. The IN operator is used to check whether values in the table are present in the list of values defined in the MySQL statement. Sample Table: Order_Details
Example:Explanation: In the above select query, the hour() function is used to extract the time value from the Order_Scheduled column in the Order_Details table, where the value of the Order_Scheduled column is either 05, 10, or 11. Output: The result of the example is given below.
Using MySQL DateTime hour function with BETWEEN OperatorWe can use the MySQL DateTime hour() function in a table to extract the hours. The MYSQL BETWEEN condition checks whether a value is within a range or not. Sample Table: Order_Details
Example:Explanation: While executing the above query, the hour() function is used to extract the time value from an Order_Schduled column in the Order_Details table where the value of the Order_Schduled column is between 05 and 10. Output: The result of the example is given below.
Next TopicMySQL date/time |
We request you to subscribe our newsletter for upcoming updates.