How to calculate working hours between two dates and times in Excel
Formula (Excel and Google Sheets)
=((NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2))*24Count full working days with NETWORKDAYS and trim the first and last day to opening hours with MEDIAN.
- Result on the example
- one result per row in
D2, filled down toD7 - Works in
- Excel 2021, 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in D2, filled down to D7. Change any input and the result updates, or edit the formula to experiment.
How it works
Every working day from the first to the last counts as a full business day: (NETWORKDAYS(B2,C2)-1) times the 8 open hours. The ends are then trimmed: MEDIAN clamps the resolved time and the opened time between opening and closing, so time before 9:00 or after 17:00 doesn't count. T-803 was opened Friday at 3:00 PM and resolved Monday at 10:00 AM: 2 hours plus 1 hour.
=((NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2))*24Result5.5
B23/2/2026 10:00The value in B2.
C23/2/2026 15:30The value in C2.
NETWORKDAYS(B2,C2)1NETWORKDAYS: Weekdays between two dates, inclusive.- start_date
B23/2/2026 10:00 - end_date
C23/2/2026 15:30
- start_date
NETWORKDAYS(B2,C2)-10The - operator subtracts.
$G$25:00 PMThe value in G2.
$G$19:00 AMThe value in G1.
$G$2-$G$10.3333333333The - operator subtracts.
NETWORKDAYS(B2,C2)-1)*($G$2-$G$10The * operator multiplies.
NETWORKDAYS(C2,C2)1NETWORKDAYS: Weekdays between two dates, inclusive.- start_date
C23/2/2026 15:30 - end_date
C23/2/2026 15:30
- start_date
MOD(C2,1)0.6458333333MOD: Remainder after division.- number
C23/2/2026 15:30 - divisor
1
- number
MEDIAN(MOD(C2,1),$G$1,$G$2)0.6458333333MEDIAN: Middle value of the numbers.- number1
MOD(C2,1)0.6458333333 - number2
$G$19:00 AM - number2
$G$25:00 PM
- number1
IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)0.6458333333IF: Returns one value if a test is true, another if false.- logical_test
NETWORKDAYS(C2,C2)1 - value_if_true
MEDIAN(MOD(C2,1),$G$1,$G$2)0.6458333333 - value_if_false
$G$25:00 PMnot used
- logical_test
NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)0.6458333333The + operator adds.
NETWORKDAYS(B2,B2)1NETWORKDAYS: Weekdays between two dates, inclusive.- start_date
B23/2/2026 10:00 - end_date
B23/2/2026 10:00
- start_date
MOD(B2,1)0.4166666667MOD: Remainder after division.- number
B23/2/2026 10:00 - divisor
1
- number
NETWORKDAYS(B2,B2)*MOD(B2,1)0.4166666667The * operator multiplies.
MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2)0.4166666667MEDIAN: Middle value of the numbers.- number1
NETWORKDAYS(B2,B2)*MOD(B2,1)0.4166666667 - number2
$G$19:00 AM - number2
$G$25:00 PM
- number1
NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2)0.2291666667The - operator subtracts.
NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2))*245.5The * operator multiplies.
In Google Sheets
The same formula works in Google Sheets: =((NETWORKDAYS(B2,C2)-1)*($G$2-$G$1)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),$G$1,$G$2),$G$2)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),$G$1,$G$2))*24. We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =LET(open,$G$1,close,$G$2,((NETWORKDAYS(B2,C2)-1)*(close-open)+IF(NETWORKDAYS(C2,C2),MEDIAN(MOD(C2,1),open,close),close)-MEDIAN(NETWORKDAYS(B2,B2)*MOD(B2,1),open,close))*24) | 5.50, 3.00, 3.00… | The same with LET, which names the opening and closing times. |
| =(C2-B2)*24 | 5.50, 19.00, 67.00…Different result | Elapsed clock hours, including nights and weekends. Counts every hour. |
Common mistakes
- It assumes the same opening hours every working day. Different hours on some days need a lookup per day.
- To skip holidays, add the holiday range as the third argument of all three NETWORKDAYS.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Calculate working hours between two dates and times
D2, calculate the business hours from opened to resolved, counting only weekdays between the opening time in G1 and the closing time in G2. Fill down to D7.Questions
How do I skip holidays too?
Add the range to each NETWORKDAYS, for example NETWORKDAYS(B2,C2,$I$2:$I$12).
How do I show the result as hours and minutes?
Leave out *24 and use the custom format [h]:mm.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.