How to Get Work Hours Between Dates And Times in Excel

Learn multiple Excel methods to get work hours between dates and times with step-by-step examples, business-ready tips, and advanced techniques.

excelformulaspreadsheettutorial
12 min read • Last updated: 7/2/2025

How to Get Work Hours Between Dates And Times in Excel

Why This Task Matters in Excel

Every organization tracks time in some form: payroll departments monitor employee hours, project managers measure effort against budgets, and customer-service teams log response times. Across these scenarios, you rarely need all the time between two timestamps—you need only the work time. In other words, you want to exclude weekends, holidays, and sometimes hours outside the standard workday. Manually subtracting one datetime from another works only if both fall inside the same work shift; once the period straddles multiple days or weekends, errors creep in quickly.

Consider a consulting firm billing clients by the hour. If an engagement starts at 3:00 PM on a Friday and ends at 10:00 AM the following Tuesday, billing the full 91 hours in between would be unethical and likely to get the invoice rejected. They need to count only paid hours—say, Monday to Friday, 9:00 AM to 5:00 PM. A similar challenge appears in manufacturing downtime analysis, IT service-level agreements, and even clinical studies that measure treatment times against staffing schedules.

Excel is uniquely suited to solving these problems because its built-in date/time engine stores every moment as a decimal day. Functions such as NETWORKDAYS, NETWORKDAYS.INTL, WORKDAY, IF, and LET give you granular control over excluding non-work periods, while custom formats and data validation help you keep inputs consistent. More advanced users can push the solution into Power Query for automated refreshes or VBA for user-defined calendars, yet 90 percent of cases can be solved with a well-designed formula. Mastering this task tightens payroll accuracy, improves project tracking, and equips you with a deeper understanding of Excel date arithmetic—a building block for dashboards, forecasting models, and time-driven KPIs.

Best Excel Approach

The most reliable formula pattern combines NETWORKDAYS (or NETWORKDAYS.INTL when you need a custom weekend schedule) with time arithmetic on the first and last days. The concept is simple:

  1. Count how many whole workdays sit fully between the two date/time stamps.
  2. Multiply those days by the length of a standard workday (for instance 8 hours).
  3. Add the remaining partial hours from the start day and from the end day, but only if those days are workdays.
  4. Optionally subtract company holidays stored in a dedicated list.

This modular logic is easy to audit, adjusts automatically when the calendar changes, and performs well even on large datasets. Use NETWORKDAYS when weekends are Saturday/Sunday; switch to NETWORKDAYS.INTL for alternative schedules like Sunday–Thursday workweeks or rotating shifts.

Recommended formula (standard Monday–Friday, 9 AM–5 PM, optional holiday list in [E2:E20]):

=LET(
  Start,A2,                       /* starting datetime */
  End,B2,                         /* ending datetime   */
  Hol,$E$2:$E$20,                 /* holiday list      */
  DayLen,("17:00"-"09:00"),       /* length of one workday */
  
  /* Whole days strictly between Start and End */
  FullDays,MAX(NETWORKDAYS(Start+1,End-1,Hol),0),
  
  /* Hours on the Start date */
  FirstDay, IF(NETWORKDAYS(Start,Start,Hol),
               MAX(MIN("17:00",MOD(End,1))-MAX("09:00",MOD(Start,1)),0),
               0),
  
  /* Hours on the End date */
  LastDay,  IF(NETWORKDAYS(End,End,Hol),
               MAX(MIN("17:00",MOD(End,1))- "09:00",0),
               0),
  
  /* Total work hours */
  (FullDays*DayLen + FirstDay + LastDay) * 24
)

Alternative for a custom weekend pattern (for instance Friday and Saturday as weekend):

=LET(
  Start,A2,
  End,B2,
  Hol,$E$2:$E$20,
  Weekend,"0000110",     /* NETWORKDAYS.INTL pattern: Fri & Sat off */
  DayLen,("17:00"-"09:00"),
  
  FullDays,MAX(NETWORKDAYS.INTL(Start+1,End-1,Weekend,Hol),0),
  
  FirstDay,IF(NETWORKDAYS.INTL(Start,Start,Weekend,Hol),
              MAX(MIN("17:00",MOD(End,1))-MAX("09:00",MOD(Start,1)),0),
              0),
  
  LastDay, IF(NETWORKDAYS.INTL(End,End,Weekend,Hol),
              MAX(MIN("17:00",MOD(End,1))- "09:00",0),
              0),
  
  (FullDays*DayLen + FirstDay + LastDay)*24
)

Parameters and Inputs

  • Start datetime (cell [A2] in examples)
    – Must be a valid Excel datetime—not text. Use consistent locale formats or ISO 8601 (yyyy-mm-dd hh:mm).
  • End datetime (cell [B2])
    – Must occur on or after the Start datetime; the formula returns zero or error otherwise.
  • Holiday list (range [E2:E20] or similar)
    – Dates only (no times) and they must exactly match the regional date system. Empty cells are ignored.
  • Workday start and end times
    – Hard-coded as \"09:00\" and \"17:00\" in the formula. Convert to decimals if you need parameter inputs: place them in named cells [StartTime] and [EndTime] to avoid hard-coding.
  • Weekend pattern
    – NETWORKDAYS assumes Saturday/Sunday as weekend. For alternative patterns pass a 7-character string to NETWORKDAYS.INTL (1 = non-working, 0 = working, starting on Monday).
  • Validation
    – Protect input cells with Data Validation set to Date or Date/Time.
  • Edge cases
    – If Start and End fall on the same non-working day, total hours appropriately return zero.
    – Crossing midnight breaks nothing; Excel stores times as fractions of a day, so 22:00 to 02:00 next day is handled by the underlying decimal value.

Step-by-Step Examples

Example 1: Basic Scenario

Objective: Calculate payable hours for a support ticket opened at 3:00 PM on Thursday 05-Apr-2029 and resolved 11:00 AM on Monday 09-Apr-2029, with standard 9-to-5 and no holidays.

  1. Enter the following data
  • [A2] = 5-Apr-2029 15:00
  • [B2] = 9-Apr-2029 11:00
  1. Insert the recommended LET formula in [C2].
  2. Formula breakdown
  • FullDays: NETWORKDAYS(Start+1,End-1) counts only Friday (since Saturday/Sunday are weekends). That returns 1 day.
  • DayLen: \"17:00\" minus \"09:00\" equals 8 hours ÷ 24 = 0.333333 day.
  • FirstDay: MIN(\"17:00\",11 AM?) Actually end time is on a later date; use MOD(Start,1)=0.625 (3:00 PM). End refers to Monday; MIN returns 5:00 PM; difference 2 hours (0.083333 day).
  • LastDay: Monday morning 11:00 AM minus 9:00 AM = 2 hours (0.083333 day).
  1. Total =(1 × 8 h)+2 h+2 h = 12 h.
  2. Format [C2] as Number with 2 decimals or Custom [h]:mm to see 12:00.

Why it works: Excel stores each datetime as a whole number of days plus a fractional remainder. NETWORKDAYS delivers whole days, while subtraction deals with fractional day parts. Splitting start/end logic guarantees you never double-count or include weekend hours.

Variations:

  • If both timestamps are on the same workday, FullDays is zero; only FirstDay or LastDay contributes.
  • Swap 9-to-5 with 7-to-3 by editing the time literals.
  • Add a holiday (e.g., Good Friday on 06-Apr-2029) to [E2]; FullDays drops to zero, lowering the total to 4 h.

Troubleshooting

  • If results return #####, the cell format is Date; change to General.
  • If you see a negative value, ensure End is after Start.

Example 2: Real-World Application

Scenario: A logistics company promises to load containers within 16 working hours of gate-in. They operate Monday-Saturday, 07:00-19:00, and close on public holidays. You need a column that flags shipments exceeding SLA.

Data layout

ABCD
Gate-InLoadedHoursBreach?
03-May-2029 11:3006-May-2029 09:10
04-May-2029 16:5505-May-2029 14:05

Steps

  1. Holiday list in [H2:H15] includes Labour Day 01-May-2029.
  2. Weekend pattern string: \"0000001\" (Sunday only off); put it in named cell [WeekendPattern] for clarity.
  3. Work shift length: 12 hours (07:00-19:00). Assign named cells [ShiftStart]=07:00 and [ShiftEnd]=19:00.
  4. Formula in [C2]:
=LET(
  s,A2, e,B2, hol,$H$2:$H$15,
  DayLen, ShiftEnd-ShiftStart,
  Full, MAX(NETWORKDAYS.INTL(s+1,e-1,WeekendPattern,hol),0),
  First, IF(NETWORKDAYS.INTL(s,s,WeekendPattern,hol),
            MAX(MIN(ShiftEnd,MOD(e,1))-MAX(ShiftStart,MOD(s,1)),0),0),
  Last, IF(NETWORKDAYS.INTL(e,e,WeekendPattern,hol),
           MAX(MIN(ShiftEnd,MOD(e,1))-ShiftStart,0),0),
  (Full*DayLen+First+Last)*24
)
  1. Copy downward.
  2. In [D2], check breach:
=IF(C2>16,"Yes","No")

Explanation:

  • At row 1, Wednesday holiday removed one working day. Full days count: Thursday and Saturday (Friday is holiday?), not exactly but example. Resulting hours might be 14.4 h—no breach.
  • Row 2 spans less than 24 calendar hours, but crossing a shift boundary counts only 10.2 h, also within SLA.

Integration considerations

  • Conditional Formatting can highlight breaches.
  • PivotTables summarize by month, average time to load, breach percentage.
  • For regular imports, add the formula to a structured Table and Power Query refreshes the raw log.

Performance: Even with 100 000 rows, LET calculation remains fast because NETWORKDAYS performs native C-level operations and the arithmetic is lightweight.

Example 3: Advanced Technique

Challenge: Global IT helpdesk offers 24×7 support except on site-specific bank holidays, with multiple time zones. You capture UTC timestamps and want to calculate business hours for each region without duplicating formulas across sheets.

Solution outline

  1. Create a Calendar table with columns Region, HolidayDate.
  2. Build a Shift table with Region, StartTime, EndTime, WeekendPattern.
  3. Use XLOOKUP inside LET to fetch the correct shift parameters dynamically based on ticket region code stored in column [C].

Formula (placed in structured Table [Tickets]):

=LET(
  s,[@OpenedUTC]+RegionOffset([@Region]),
  e,[@ClosedUTC]+RegionOffset([@Region]),
  hol, FILTER(Calendar[HolidayDate], Calendar[Region]=[@Region]),
  shiftStart, XLOOKUP([@Region],Shift[Region],Shift[StartTime]),
  shiftEnd,   XLOOKUP([@Region],Shift[Region],Shift[EndTime]),
  weekend,    XLOOKUP([@Region],Shift[Region],Shift[WeekendPattern]),
  
  dayLen, shiftEnd-shiftStart,
  full, MAX(NETWORKDAYS.INTL(s+1,e-1,weekend,hol),0),
  first, IF(NETWORKDAYS.INTL(s,s,weekend,hol),
            MAX(MIN(shiftEnd,MOD(e,1))-MAX(shiftStart,MOD(s,1)),0),0),
  last, IF(NETWORKDAYS.INTL(e,e,weekend,hol),
           MAX(MIN(shiftEnd,MOD(e,1))-shiftStart,0),0),
  (full*dayLen+first+last)*24
)

The custom LAMBDA RegionOffset converts UTC to local time. Because each parameter is looked up, you maintain one formula for all regions. Auditing is easy: inspect the Shift/Calendar tables rather than hunting hard-coded literals.

Performance tips

  • Convert Calendar and Shift tables to dynamic arrays so FILTER returns spill ranges instead of volatile INDIRECT.
  • Cache XLOOKUP results by nesting them inside LET variables, as shown, to avoid repeated lookups.
  • If holidays exceed 500 rows, index them by region year for faster FILTER.

Error handling

  • Wrap the final result in IFERROR(..., \"Config Error\") to catch missing region codes.
  • Add Data Validation on Region to prevent typos.

Tips and Best Practices

  1. Name your parameters: Put shift start/end and weekend patterns in named cells or a control sheet. Hard-coded literals are brittle.
  2. Use LET for readability: Splitting the calculation into variables makes debugging painless and speeds up large models.
  3. Store holidays once: Keep a dedicated Holiday table and reference it throughout the workbook instead of copying lists into each sheet.
  4. Format as [h]:mm: This custom number format shows cumulative hours above 24 (e.g., 149:30). Avoid Time formats that wrap at midnight.
  5. Audit with test cases: Add known scenarios (same-day ticket, weekend only, holiday only) and assert expected outputs. This catches logic drift during updates.
  6. Document assumptions: Note the business hour rules beside the formula so successors understand that 09:00-17:00 applies—or when it changes to 08:30-16:30, they know where to adjust.

Common Mistakes to Avoid

  1. Treating text as dates: If Start or End is stored as \"2029-05-03 11:30\" text, subtraction fails. Convert with VALUE or set cell format to Date/Time.
  2. Forgetting time zones: When importing from systems that stamp timestamps in UTC, adjust to local schedule or you will under- or over-count.
  3. Ignoring holidays: People often pass an empty holiday list during testing and forget to add it later; the result inflates hours every Christmas and New Year.
  4. Hard-coding weekend pattern: Saturday/Sunday may be obvious to you but not to the Dubai office. Use NETWORKDAYS.INTL with pattern string variables.
  5. Double-counting boundary hours: Misplacing the plus/minus one day in FullDays (Start+1, End-1) causes first and last days to be counted twice. Always test a case that spans exactly one full workday to confirm count = 8 hours.

Alternative Methods

MethodProsConsBest Use
NETWORKDAYS + arithmetic (this tutorial)Native, no add-ins, fast, supports holiday lists, works in Excel 2007+Requires separate logic for start/end day; not flexible for split shiftsStandard office schedules, large datasets
Power QueryGUI-driven, refreshable, easy to incorporate complex calendars, outputs static table (no recalc lag)Requires refresh, not suitable for real-time entry, refresh is slower than formulasDaily ETL jobs, importing logs from systems
VBA UDF (User-Defined Function)Full control, can store calendars in arrays, can process micro-secondsRequires macros enabled, potential security warnings, slower per-cell than worksheet functionsHighly customised calendars, extremely long hour ranges
DAX in Power BIIntegrates with dashboards, contextual filteringOutside Excel grid, learning curveEnterprise reporting, interactive visuals

When to migrate:
– Start with the formula approach.
– If the holiday calendar changes weekly or you need automatic region lookups, move to Power Query.
– If you face multi-shift manufacturing schedules with breaks, VBA or database solutions may be necessary for speed.

FAQ

When should I use this approach?

Use it whenever you have two datetime stamps and need paid or SLA hours excluding weekends and holidays. Typical examples: payroll, ticket resolution time, equipment downtime, and contract billing.

Can this work across multiple sheets?

Yes. Store the formula in one central sheet and reference other sheets with qualified ranges (e.g., \'LogEntries\'!A2). Ensure absolute references to the holiday list so every sheet points to the single source of truth.

What are the limitations?

The pattern assumes a single contiguous work shift per day. If your schedule has lunch breaks or multiple shorter shifts, you need to adapt the logic or switch to VBA. Also, NETWORKDAYS caps at serial dates within Excel’s date system (years 1900–9999).

How do I handle errors?

Wrap the formula in IFERROR to catch issues like invalid dates. For logic errors, create test harness cases: start and end on the same weekend day should return zero; start Monday 9 AM, end Monday 5 PM should return 8 hours.

Does this work in older Excel versions?

NETWORKDAYS exists in Excel 2003, but NETWORKDAYS.INTL and LET require Excel 2013 and Microsoft 365 respectively. If you are on Excel 2010, replace LET with nested functions, and simulate custom weekends by adding a helper column.

What about performance with large datasets?

On 100 000 rows, LET with NETWORKDAYS averages under half a second on modern hardware. Avoid volatile functions like TODAY inside each row. Consider turning calculation to Manual while bulk-pasting data, then press F9.

Conclusion

Mastering the calculation of work hours between dates and times unlocks accurate payroll, trustworthy SLAs, and defensible billing—all without leaving Excel. The NETWORKDAYS family paired with basic time arithmetic delivers a versatile, high-performance solution for most schedules, and the LET function keeps your formulas tidy and maintainable. Practice the examples, adapt the parameters to your organization’s calendar, and soon you’ll integrate these techniques into dashboards, Power Query pipelines, and what-if analyses. Keep experimenting, stay mindful of time zones and holidays, and you’ll wield Excel’s date engine with confidence across any time-driven challenge.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.