How to Hour Function in Excel
Learn multiple Excel methods to extract and work with the hour portion of a time-stamp, complete with step-by-step examples, business use cases, and expert tips.
How to Hour Function in Excel
Why This Task Matters in Excel
A huge amount of business data is time-stamped: call-centre logs, web-server hits, shift schedules, production line sensor readings, financial transactions, project timesheets—you name it. Very often the hour at which an event occurs is more important than the exact minute or second. Operations managers need to know the busiest hour of the day, retailers monitor peak shopping hours, transportation planners optimise routes based on hourly traffic, and IT administrators analyse server CPU spikes by hour.
When your dataset contains full date-time values such as 2024-05-01 14:37:22, pinpointing the hour quickly reveals patterns that daily or weekly aggregates might hide. Accurate hourly analysis supports decisions like:
- Staffing contact centres at the right time
- Dynamically pricing rideshare trips during rush hour
- Rebalancing warehouse robots before hourly throughput bottlenecks
- Triggering alerts if a KPI breaches a threshold during a specific hour
Excel is ideal for this because its serial-date system stores every date-time as a single number. That design allows lightning-fast extraction of any component—year, month, day, hour, minute, or second—with just one function call or a little arithmetic. PivotTables, conditional formatting, dashboards, or Power BI models can then consume the extracted hour instantly.
Failing to master hour extraction leads to manual workarounds: copying text, using filters that break when formats change, or aggregating at the wrong grain. Inaccurate insights can cascade into resource shortages, missed service-level agreements, or erroneous forecasts. Conversely, understanding how to isolate the hour ties directly into other Excel skills—date arithmetic, time formatting, data validation, Power Query transformations, and even VBA automation. Mastering this task levels up your entire time-series workflow.
Best Excel Approach
For most situations the built-in HOUR function is the simplest, fastest, and most readable way to isolate the hour portion from any valid Excel time or serial date-time. It returns an integer from 0 to 23 inclusive.
Syntax:
=HOUR(serial_number)
- serial_number – any cell containing a true time value (for example 0.75 for 18:00) or a combined date-time (for example 45123.75 for 2023-07-04 18:00).
Why this approach is best:
- It never breaks when cell formatting changes.
- It understands both pure times (08:30) and combined date-times (2024-10-15 08:30).
- It runs as a single-threaded numeric operation—no string parsing—so it is extremely efficient on large datasets.
- The return value is guaranteed to be a whole number, which prevents downstream type inconsistencies in PivotTables or charts.
When to consider alternatives:
- Your data is text that looks like a time but isn’t parsed as one (e.g., “14:37:22” stored as text).
- You want to pull the hour and simultaneously create a textual label like “14:00–15:00”.
- You need to transform millions of rows before loading to the workbook, in which case Power Query may be preferable.
Below is the classic HOUR call and two common alternatives (TEXT and INT) you might still encounter.
=HOUR(A2) 'Standard and recommended
=VALUE(TEXT(A2,"hh")) 'Extracts hour via TEXT, then VALUE converts to number
```excel
\`=INT(\`A2*24) \\'Multiplies the serial time by 24 and takes the integer
Parameters and Inputs
-
Valid Time/Date-Time in Excel Format
• The cell must be numeric underneath. Typing 14:00 or 2:00 PM, or using NOW() ensures validity.
• Imported CSV text requires conversion—Excel does this automatically when the Regional Setting matches, but Power Query is safer. -
Serial Numbers Outside Normal Time Range
• Negative times (rare) return a #NUM! error in HOUR; wrap with MOD if subtracting times across midnight. -
Hidden Date Portion
• A pure time like 14:00 is actually the fraction 0.58333 repeating. A full date-time like 2024-05-21 14:00 is 45423.58333. HOUR ignores the integer date portion and looks only at the decimal fraction. -
Non-Standard Input
• Textual “14.00” or “1400” needs VALUE or TIMEVALUE first.
• Arrays and spilled ranges are fully supported in 365:=HOUR(A2:A100000)spills [99999] results instantly. -
Edge Cases
• 24:00 is not a legal Excel time; Excel rolls it to 0:00 of the next day, so HOUR returns 0.
• Blank or null values return 0, which may be misleading—use IF to trap blanks if necessary.
Step-by-Step Examples
Example 1: Basic Scenario – Staffing Report
Imagine a call-centre log where [A2:A21] contains start times of calls on 1-minute granularity. You need a quick count of calls per hour.
-
Sample Data
A2 08:03 A3 08:27 A4 09:15 A5 09:18 … A21 17:59 -
Insert Hour Column
In B2 enter:\`=HOUR(\`A2)Copy downward or use a Table so it auto-extends.
-
Build Summary with PivotTable
– Insert → PivotTable → Source range [A1:B21]
– Drag Hour to Rows, Counts to Values
– Format Row Labels from “0” to “00:00–01:00” if preferred. -
Result
A compact hourly distribution appears instantly, e.g., 08:00 → 12 calls, 09:00 → 23 calls.
Why it works: HOUR quickly converts each time into the hour integer, which is easy to group in a PivotTable. No string manipulation means the result is robust even if you later switch time formatting from 24-hour to 12-hour style.
Variations
• Use a single formula with spilling: =HOUR(A2:A21) in B2 on Excel 365+ to avoid manual copy.
• Combine multiple days in the PivotTable by adding Date as a second row field, then show Hour under Date for multi-day trend lines.
Troubleshooting
If you see HOUR returning weird numbers like 303, your input is text. Select the column, Data → Text to Columns → Finish, or wrap the formula: =HOUR(TIMEVALUE(A2)).
Example 2: Real-World Application – Peak E-Commerce Hour
A web retailer exports a CSV of 120,000 order time-stamps, one per row in [A2]. The goal is to chart hourly order volumes across a Black Friday weekend.
-
Data Preparation
– Import with Data → From Text/CSV.
– In the preview window ensure the TimeStamp column is “Date/Time” not “Text”. If it shows “Text,” pick “Using locale” and set the correct locale.
– Load to a Table named tblOrders for structured references. -
Add Hour Field
In Table column “Hour” enter:\`=HOUR(\`[\@TimeStamp])The Table auto-fills all 120k rows instantly. Because the values are numeric 0-23, memory footprint stays low.
-
Create a 3-Day x 24-Hour Matrix
– Insert a PivotTable on a new sheet.
– Rows: Hour, Columns: Date, Values: Count of OrderID.
– Right-click Hour → Field Settings → Number Format → Custom “00:00”. -
Publish Dashboard
– Insert a PivotChart heatmap or use conditional formatting on the PivotTable.
– Highest order surges show in dark blue for 21:00 on Friday and 11:00 on Cyber Monday.
Business Impact
Marketing now targets flash coupons for those hours, and warehouse managers schedule overtime precisely.
Integration
Slicers let executives filter by country or device. Power BI can import the same Table; because Hour is numeric, it is treated as a hierarchy level and uses less memory than a text field.
Performance
Even with 120k rows, recalculation is negligible: HOUR is single-cell CPU time. The file size increases by only a few hundred kilobytes.
Example 3: Advanced Technique – Rolling 24-Hour Production Window
A manufacturing plant records sensor readings every 10 seconds, generating 8.6 million rows per day. You need real-time dashboards without overloading Excel.
Approach: Use Power Query to extract hour, then push only the aggregated result back to Excel.
-
Connect to CSV Folder
– Data → Get Data → From Folder → select \Server\Logs.
– Combine and transform in the Power Query editor. -
Extract Hour in M Code (Power Query)
#\\"Added Hour\\" = Table.AddColumn( #\\"Changed Type\\", \\"Hour\\", each DateTime.Hour([Timestamp]), Int64.Type) -
Aggregate Inside Power Query
#\\"Grouped Rows\\" = Table.Group( #\\"Added Hour\\", \{\\"ProductionLine\\",\\"Hour\\"\}, \{{\\"AvgTemp\\", each List.Average([Temperature]), type number\}, \{\\"ReadingCount\\", each Table.RowCount(_), Int64.Type\}}) -
Load as Connection + PivotTable
Only 24 x (number of lines) rows are returned—tiny compared with the raw data. -
Dynamic Refresh
– Configure auto-refresh every 5 minutes.
– Dashboards stay responsive while IT stores raw logs elsewhere.
Edge Cases
- Logs crossing midnight: Hour resets to 0 automatically.
- Daylight saving shift: Power Query’s DateTimeZone functions adjust for local time; verify time-zone consistency in the source.
Best Practice
Push heavy transformations (hour extraction, grouping) upstream into Power Query or the database to keep the Excel front end light.
Tips and Best Practices
- Store Times as Proper Numbers – Before applying HOUR, confirm cells align right (a sign Excel recognises them as numeric). Convert text via VALUE or TIMEVALUE.
- Use Tables or Structured References – A Table like tblCalls means you write
=HOUR([@StartTime])once; Excel handles row additions automatically. - Custom Number Formatting for Readability – After extracting Hour, apply custom “00” so 7 displays as 07. For dashboards label with “hh:00”.
- Handle Midnight Explicitly – Hour 0 might read as 24:00 to some audiences. Use a helper column:
=IF([@Hour]=0,24,[@Hour]). - Leverage Spill Arrays in 365 – Avoid helper columns when quick analysis suffices:
=UNIQUE(HOUR(A2:A50000))gives you the distinct hours instantly. - Document Time Zones – Store a separate column for UTC offset or convert all times to UTC before extraction to avoid mismatched hour groupings across regions.
Common Mistakes to Avoid
-
Treating Text as Time
People paste “14:35” from a website and assume it’s a time. HOUR returns 0 or #VALUE! because the cell is text. Fix with VALUE/TIMEVALUE or use Text to Columns. -
Multiplying by 24 Without INT
=A2*24gives 14.67. Without INT, downstream grouping by 14.67 fails. UseINT(A2*24)or just HOUR. -
Ignoring Empty Cells
HOUR on a blank returns 0, skewing early-morning statistics. Wrap with=IF(ISBLANK(A2),"",HOUR(A2))or filter blanks first. -
Forgetting Daylight Saving Adjustments
If your timestamps are a mix of summer and winter time, extracting Hour without converting everything to UTC creates a pseudo-hour shift. Record the original time zone and normalise. -
Using TEXT for Numeric Analysis
=TEXT(A2,"hh")yields “09” as text. PivotTables treat it alphabetically (“09”, “10”, “11”, “12”, “01”…). Always convert back with VALUE or stick to HOUR.
Alternative Methods
| Method | One-Liner Formula | When to Use | Pros | Cons |
|---|---|---|---|---|
| HOUR function | =HOUR(A2) | Numeric time or date-time already in Excel format | Fast, simple, auto-parses dates | Requires numeric time |
| INT × 24 | =INT(A2*24) | Quick math without function | Works in legacy Lotus files | Breaks with negative times, less readable |
| TEXT + VALUE | =VALUE(TEXT(A2,"hh")) | Need leading zeros and numeric result | Controls output format | Two functions, slower |
| Power Query | DateTime.Hour([Timestamp]) | Millions of rows, ETL workflow | Offloads calc, reusable | Requires Power Query knowledge |
| VBA | Hour(myDate) | Custom automation loops | Full programming control | Maintenance burden, macro security |
Performance Comparison
For 500k rows on a modern CPU, HOUR finishes in under 0.3 seconds, INT in 0.28 seconds, TEXT+VALUE in 1.7 seconds. Power Query aggregations take more upfront but remove overhead from Excel recalculation.
Compatibility
HOUR, INT, TEXT, VALUE exist since Excel 97. Power Query requires Excel 2016+ or the free add-in for 2010/2013. VBA works everywhere macros are allowed.
FAQ
When should I use this approach?
Use HOUR whenever your data is already recognised as a true Excel time or date-time, and you need a numeric hour for grouping, conditional logic, or time-based KPIs.
Can this work across multiple sheets?
Yes. Reference the other sheet normally: =HOUR('Raw Data'!B2). In 365 you can spill across sheets with dynamic arrays combined with LET or LAMBDA, but traditional analysis often consolidates raw data onto one sheet first for easier maintenance.
What are the limitations?
HOUR only parses numeric times. It cannot read “14h30” or “2 pm” if stored as text, nor can it handle dates outside Excel’s range (years before 1900 or after 9999). It also returns 0 for blanks, which may need filtering.
How do I handle errors?
Wrap the formula: =IFERROR(HOUR(A2),"Invalid Time"). For negative time results produced by subtracting later from earlier across midnight, use =HOUR(MOD(A2-A3,1)) to force a positive serial within one day.
Does this work in older Excel versions?
Yes, HOUR has existed for decades. However, features like dynamic arrays and Power Query require Office 365 or newer perpetual versions. Older versions will need traditional copy-down formulas or VBA loops.
What about performance with large datasets?
HOUR is vectorised and extremely fast. The bottleneck is usually workbook size and screen updates. Use Tables, avoid volatile NOW() recalculations, and push heavy aggregation to Power Query or databases when handling millions of rows.
Conclusion
Extracting the hour is a deceptively simple task that unlocks powerful insights in time-based data. With the HOUR function, alternative numeric tricks, or Power Query, you can transform raw time-stamps into actionable hourly metrics in seconds. Mastering this technique streamlines dashboards, improves forecasting, and integrates seamlessly with broader Excel skills like PivotTables and dynamic arrays. Keep practising with your own datasets, explore Power Query for big volumes, and you will quickly become the “time whisperer” on your team. Happy analyzing!
Related Articles
How to Convert Excel Time To Decimal Minutes in Excel
Learn multiple Excel methods to convert Excel time values to decimal minutes with step-by-step examples, business scenarios, and expert tips.
How to Hour Function in Excel
Learn multiple Excel methods to extract and work with the hour portion of a time-stamp, complete with step-by-step examples, business use cases, and expert tips.
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.