If you're working with Excel and need to extract the hour from a time value, there are a few simple ways to do it. In this blog post, we'll explore different methods to retrieve the hour only from a time value in Excel, providing you with the flexibility to choose the one that suits your needs.
Method 1: Using the HOUR Function

The HOUR function in Excel is specifically designed to extract the hour component from a time value. Here's how you can use it:
- Select the cell where you want the hour to be displayed.
- Enter the formula
=HOUR(A1)
, replacingA1
with the cell reference containing the time value. - Press Enter, and the hour will be displayed in the selected cell.
For example, if cell A1
contains the time 14:30, using the formula =HOUR(A1)
will return 14 as the hour value.
Method 2: Using a Custom Number Format

Excel also allows you to format a time value to display only the hour using a custom number format. Follow these steps:
- Select the cell or range of cells containing the time values.
- Right-click and choose Format Cells from the context menu.
- In the Format Cells dialog box, go to the Number tab.
- Under Category, select Custom.
- In the Type box, enter
hh
and click OK.
This format will display only the hour component of the time value. For instance, if cell A1
contains the time 14:30, applying this custom format will show 14 as the hour.
Method 3: Using the TEXT Function

Another approach is to use the TEXT function in Excel, which allows you to convert a time value into a text format. Here's how:
- Select the cell where you want the hour to be displayed.
- Enter the formula
=TEXT(A1,"hh")
, replacingA1
with the cell reference containing the time value. - Press Enter, and the hour will be displayed as text in the selected cell.
The "hh"
format code in the TEXT function specifies that only the hour component should be extracted and displayed.
Method 4: Extracting Hour Using VBA

If you're comfortable with Visual Basic for Applications (VBA), you can create a custom function to extract the hour from a time value. Here's a simple VBA function to achieve this:
Function GetHour(TimeValue As Variant) As Integer
GetHour = Hour(TimeValue)
End Function
To use this function, follow these steps:
- Open the Visual Basic Editor by pressing ALT + F11 or selecting Developer > Visual Basic in Excel.
- Insert a new module and paste the code into it.
- Close the Visual Basic Editor and return to Excel.
- In the desired cell, enter the formula
=GetHour(A1)
, replacingA1
with the cell reference containing the time value. - Press Enter, and the hour will be displayed using the custom VBA function.
Choosing the Right Method

The method you choose depends on your specific needs and preferences. If you're working with a small number of time values, using the HOUR function or the TEXT function might be sufficient. For larger datasets or more complex requirements, the custom number format or VBA function can provide efficient solutions.
Conclusion

In this blog post, we explored various methods to extract the hour from a time value in Excel. Whether you prefer built-in functions, custom number formats, or VBA, Excel offers a range of options to meet your needs. By understanding these methods, you can efficiently work with time values and extract the hour component as required.
Can I use these methods with time values in different formats?
+Yes, these methods work with various time formats, including 12-hour and 24-hour formats. Excel automatically recognizes and handles different time formats.
Is it possible to extract other time components, like minutes or seconds, using similar methods?
+Absolutely! Excel provides functions like MINUTE and SECOND to extract these components. You can apply similar techniques to extract specific time components.
Can I combine these methods to extract multiple time components in a single cell?
+Yes, you can use concatenation or other formulas to combine the extracted hour, minute, and second components in a single cell.