Count working days of a date interval (period) inside another given date interval (period) - excel

I have several periods. Right now I use a formula to count how many days fall within one period taking another period into account.
For example period 1 has 26 days that fall within the project period. There can be many project periods, but period 1 to 12 will be the same always
Project Period : 20-12-2018 to 15-03-2019
Period 1: 15-12-2018 to 14-01-2019 (26 days)
Period 2: 15-12-2018 to 14-02-2019 (31 days)
Period x etc.
=IF(MAX(MIN($N$7;O4)-MAX($M$7;O3)+1)<0;0;MAX(MIN($N$7;O4)-MAX($M$7;O3)+1))
I need to find out how many working days of period 1,2...12. fall within the project period. The result should be 13 for period 1, when subtracting holidays and weekends. For that I'm using the
=NETWORKDAYS(M7;O4;Holidays)
How do I achieve that?

Assuming that cells A1 & B1 include start and end dates for the project and A2 and B2 are the start and end dates for period 1:
=NETWORKDAYS(MAX($A$1,A2),MIN($B$1,B2))
This will give you the number for workdays in the period (Monday through Friday).
If you want to exclude holidays like 31-12-2018 or 01-01-2019 you need to provide a list of holidays as the optional third argument.
For example, if you have a list of holidays you want to exclude in column F row 1 to 10 your formula would be
=NETWORKDAYS(MAX($A$1,A2),MIN($B$1,B2),F1:F10)
In case you do not want to exclude weekends use the DAYS function instead but be aware that in this function the first argument is the end date while the second argument is the start date.

Related

how to do 2 seperate operations if start time of shift is before 7 but end time is after 7

I'm trying to make an excel sheet where I only need to put in start and end time and excel chooses the correct pay rate and how many hours I've worked (already done) and outputs how much I've earned. So far I have a column (D) for the date of shift (DAY, day of month, Month, year) column for hours worked (E), column for start time and end time (F, G) I have already written the formula to calculate the hours worked but in Australia where I live my pay rate increases after 7 PM, and increases again after 12 AM. Is there a way to have excel automatically know that it needs to take the hours worked before 7 PM and multiply it by a 24.41, then the hours worked between 7 PM and 12 AM by 26.54 etc, if my shift starts for example at 5:30 pm and ends at 3 AM?
These are the different payrates at the different times: (Time is in cell A1, Pay rate is B1, etc)
Time Pay Rate
Regular $24.41
Mon-Fri 7pm-midnight $26.54
Mon-Fri 7midnight-7am $27.60
Saturday $29.30
Sunday $34.18
Public Holidays $48.83
Thanks in advance
Solutions to all of these type of questions use the standard formula for overlapping time periods
=max(0,min(end1,end2)-max(start1,start2))
The best way to do it IMO is to simplify it two ways
(1) By splitting any times that cross through midnight into two parts, one up to midnight and one from midnight onwards
(2) Using a lookup table to match the conditions (day of week and time of day) to the payscale.
Then use an array formula to do the lookup and calculation. Because you can't use MAX and MIN as above in an array formula, you have to write it out using if statements and the formula gets pretty long
=SUM((WEEKDAY(E2,2)>=PayRates!$A$2:$A$10)*(WEEKDAY(E2,2)<=PayRates!$B$2:$B$10)*24*PayRates!$E$2:$E$10*
IF(IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)<0,0,
IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)))
This has to be entered using CtrlShiftEnter
This is how my pay rates are arranged
NB When the finishing time of a pay rate is midnight, it is entered as 1 (you want it to be 24:00, but entering 24:00 just gives you the same as 00:00)
And this is the main sheet
With the following columns
A,B and C are your input.
Split
=B2<A2
StartDate1 and StartTime1 are just a copy of your input
EndTime1
=IF(Split,1,B2)
StartDate2
=E2+Split
StartTime2
00:00
EndTime2
=IF(Split,B2,0)
Total1
The main formula
Total2
The main formula copied across by four columns to give any pay for the second day when the shift goes through midnight.
Total
Total1+Total2
Public holidays can be added fairly easily.

Count number of hours between 2 dates excluding weekends and between 10pm - 10am?

I'm trying to calculate the number of hours between two date/times, excluding bank holidays and between 10pm and 10am.
I've got the Start Datetime in B3, and then End Datetime in G3. In SLA B13 - B22, I have a list of the bank holiday dates for 2015, and I am using the following forumal
=SUM(G3-B3-COUNTIFS(SLA!B13:B22,">"&B3,SLA!B13:B22,"<"&G3))
For some reason, I cant get this to exclude bank holidays, however I then also nee to take into account the 10pm - 10am bracket.
Can anyone help?
=NETWORKDAYS(B3;G3;SLA!B13:B22)*12
*12 because only 12 hours per day count (exclude time between 10 pm and 10 am)
I've tried your formula and it works fine for whole days for me, as long as you format the cell containing the formula as general or number to avoid formatting it as a date. It doesn't exclude weekends of course which presumably is what you want.
You might want to add 1 to make it inclusive, make > into >= and < into <= in case the start and end dates are bank holidays and multiply by 12 to get the result in hours:-
=(G3-B3+1-COUNTIFS(SLA!B13:B22,">="&B3,SLA!B13:B22,"<="&G3))*12
You could calculate the hours worked directly from datetime values: the basic formula would be:-
=(G3-B3)*24-(INT(G3)-INT(B3))*12
i.e. subtracting 12 hours for each complete day.
You could also exclude the holidays (if between the start and end dates):-
=(G3-B3)*24-(INT(G3)-INT(B3)+COUNTIFS(SLA!B13:B22,">"&B3,SLA!B13:B22,"<"&G3))*12
i.e. subtracting a further 12 hours for each day's holiday.
One more thing you could do is to apply an adjustment for start and end time to the Networkdays formula by adding:-
=MOD(G3,1)-MOD(B3,1)

Calculate the time between two dates, excluding business hours and holidays

How to calculate the time between two dates, excluding business hours and holidays, using Excel or in Salesforce platform?
Assuming the earlier date is in A1 and the later in B1 then:
=24*(B1-A1-1)-8*(NETWORKDAYS(A1,B1)-2)-16*(NETWORKDAYS(A1,B1)-2 -(NETWORKDAYS(A1,B1,holidays)-2))
I have not condensed the above as you may wish to make adjustments.
The part starting 24* is the total number of hours (excluding shifts in clocks) between the two dates. Between does not count either -after the earlier and before the later.
The part starting 8* is the total number of hours that are to be excluded on the basis that they are working hours. Here I have assumed an eight hour day. What counts as a weekend (standard non-working days) is as decided by Microsoft. For more flexibility about that use NETWORKDAYS.INTL, if available.
The part starting 16* is the total number of hours to be excluded (that have not already been) on the basis that they are holidays. These days are calculated as the difference between working days assuming no holidays and working days excluding holidays, with the latter excluded through the optional third function parameter which here is a range named holidays.
The result I get from A1 = 31/12/2014 and B1 = 12/01/2105 is 192, assuming Saturdays and Sundays are weekend days and 1/1/15 is in holidays, which may be calculated as four weekend days (96 hours) plus six work days (#16 hours = 96).

Calculate number of specific days in range

How can I count the (fractional) count of specific day of the week in a range? For instance, if the range is from Monday, June 3 12:00 P.M. to Tuesday June 4 12:00 P.M., and I want to count the number of Mondays, the formula would return the result 0.5.
I've already found a formula for the integer number of days:
=SUM(INT((WEEKDAY($B2-x)+$D2-$B2)/7))
where x is the day of the week of interest (1 to 7). Of course, it would need to be modified to return the aforementioned result. How would I do so?
You can get the total number of Mondays (including both start and end date) with this version (you don't need SUM)
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)
...and then do an adjustment to take into account the start/end days, e.g.
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)-IF(WEEKDAY($D2)=2,1-MOD($D2,1))-IF(WEEKDAY($B2)=2,MOD($B2,1))
I don't really recommend it (it's much more resource-hungry) but this version should give you the same result
=SUMPRODUCT((TEXT(B2+(ROW(INDIRECT("1:"&ROUND((D2-B2)*1440,0)))-0.5)/1440,"ddd")="mon")+0)/1440
It tests every minute within the date range to ascertain whether or not it falls on a Monday (assumes that you don't go down to seconds)

Elapsed Days Hours Minutes Excluding Weekends and Holidays Time

This sounds simple but I have been pulling my hair out trying to figure out a solution. Any help before I go bald would be great.
I need a formula which is able to
calculate the duration in (days, hrs, mins) between two date\time values (eg 05/12/2012 5:30 PM and say 07/12/2012 5:45 PM);
excluding weekends and holidays.
I would like the result of the formula to read as follows "e.g 2 Days 0 Hrs and 15 Mins".
Thanks
Link to sample workbook
You can use NETWORKDAYS and NETWORKDAYS.INTL to achieve this
A bit of manipulation is required as these return net whole days:
Use these functions to calculate the number of non workdays, then subtract from the difference between start and end dates
=E3-D3-(NETWORKDAYS.INTL(D3,E3,"0000000")-NETWORKDAYS(D3,E3,$A$16:$A$24))
This returns the working day difference, where 1.0 = 1 day
NETWORKDAYS.INTL(D3,E3,"0000000") calculates whole days between the two dates (no weekends, no holidays)
NETWORKDAYS(D3,E3,"0000000",$A$16:$A$24) calculates whole working days days between the two dates (Sat/Sun weekends, holidays as per your list in $A$16:$A$24)
Difference in non-working days between the two dates.
E3-D3 is time between start and end date/times (1.0 = 1 day)
Use custom number formatting to display thye result in the format you require
d "Days" h "Hours" mm "Mins"
Note: this format won't work for negative values, you will need an alternative for when end date is before start date.
The following formula works like a treat with no additional formatting or manipulation.
To make it more stable I have turned all the holiday dates for UK 2012/13 into ‘Excel Serial Number’ format and placed them in an array bracket.
Replacing the "D5" in the formula with your cell reference for your course or metric "End Date" and "E5" with your course or Metric for "Completion Date".
=IF(E5<D5,"-"&TEXT(D5-E5,"h:mm"),NETWORKDAYS(D5,E5,({40910,41005,41008,41036,41064,41065,41148,41268,41269,41275,41362,41365,41400,41421,41512,41633,41634}))-1-(MOD(E5,1)<MOD(D5,1))&" days "&TEXT(E5-D5,"h:mm"))

Resources