In cell G2
, you can put the following formula:
=LET(from,A2:A4,to,B2:B4,holidays,C2:C2,startHr,E1,endHr,E2, lunchS, E3, lunchE, E4,
CALC, LAMBDA(date,isFrom, LET(noWkDay, NETWORKDAYS(date,date,holidays)=0,
IF(noWkDay, 0, LET(d, INT(date), start, d + startHr, end, d + endHr,
noOverlap, IF(isFrom, date > end, date < start), lunchDur, lunchE-lunchS,
ls, d + lunchS, le, d + lunchE,
isInner, IF(isFrom, date > start, date < end),
diff, IF(isFrom, end-date-1 - IF(date < ls, lunchDur, 0),
date-start-1 - IF(date > le, lunchDur, 0)),
IF(noOverlap, -1, IF(isInner, diff, 0)))))),
MAP(from,to,LAMBDA(ff,tt, LET(wkdays, NETWORKDAYS(ff,tt,holidays),
duration, wkdays + CALC(ff, TRUE) + CALC(tt, FALSE),
days, INT(duration), time, duration - TRUNC(duration),
TEXT(days, "d") &" days "& TEXT(time, "hh:mm") &" hrs "
)))
)
and here is the output:

Explanation
Used LET
function for easy reading and composition. The main idea is first to calculate the number of working days excluding holidays
from column value to to column value. We use for that NETWORKDAYS
function. Once we have this value for each row, we need to adjust it considering the first day and last day of the interval, in case we cannot count as a full day and instead considering hours. For inner days (not start/end of the interval) it is counted as an entire day.
We use MAP
function to do the calculation over all values of from
and to
names. For each corresponding value (ff
, tt
) we calculate the working days (wkdays
). Once we have this value, we use the user LAMBDA
function CALC
to adjust it. The function has a second input argument isFrom
to consider both scenarios, i.e. adjustment at the beginning of the interval (isFrom = TRUE
) or to the end of the interval (isFrom=FALSE
). The first input argument is the given date
.
In case the input date
of CALC
is a non working day, we don't need to make any adjustment. We check it with the name noWkDay
. If that is not the case, then we need we need to determine if there is no overlap (noOverlap
):
IF(isFrom, date > end, date < start)
where start
, end
names correspond to the same date as date
, but with different hours corresponding to start Hr and end Hr (E1:E2
). For example for the first row, there is no overlap, because the end date doesn't have hour information, i.e. (12:00 AM
), in such case the corresponding date should not be taken into account and CALC
returns -1
, i.e. one day needs to be subtracted.
In case we have overlap, then we need to consider the case the working hours are lower than the maximum working hours (from 9:00
to 18:00
). It is identified with the name isInner
. If that is the case, we calculate the actual hours. We need to subtract 1
because it is going to be one less full working day and instead to consider the corresponding hours (that should be less than 9hrs
, which is the maximum workday duration). The calculation is carried under the name diff
:
IF(isFrom, end-date-1 - IF(date < ls, lunchDur, 0),
date-start-1 - IF(date > le, lunchDur, 0))
If the actual start is before the start of the lunch time (ls
), then we need to subtract lunch duration (lunchDur
). Similarly if the actual end is is after lunch time, we need to discount it too.
Finally, we use CALC
to calculate the interval duration
:
wkdays + CALC(ff, TRUE) + CALC(tt, FALSE)
Once we have this information, it is just to put in the specified format indicating days and hours.
Now let's review some of the sample input data and results:
- The interval starts on Monday
7/25
and ends on Friday 7/29
, therefore we have 5
working days, but 7/26
is a holiday, so the maximum number of working days will be 4
days.
- For the interval
[7/25, 7/29]
starts and ends on midnight (12:00 AM
), therefore the last day of the interval should not be considered, so actual working days will be 3
.
- Interval
[7/25 10:00, 7/29 17:00]
. For the start of the interval we cannot count one day, instead 8hrs
and for the end of the interval, the same situation 8hrs
, so instead of 4days
we are goin to have 2days
plus 16hrs
, but we need to subtract in both cases the lunch duration (1hr
) so the final result will be 2 days 14hrs
.