Sum of work hours between two dates with changing shifts

Myrko

Board Regular
Joined
Jan 26, 2015
Messages
77
Hello,

I've tried how to calculate how many work hours were there between two dates when I have one work time during regular workdays and another work time during weekend (let's say Saturdays and Sundays have same work time for this example).

So I want to calculate how many working hours passed from 1/26/2015 12:37 PM to 2/2/2015 5:59 AM when work time from Monday to Friday is from 8:00 AM to 16:00 PM and on weekends work time is from 9:00 AM to 13:00 PM.

DaysStartEnd
Mon-Fri8:0016:00
Sat-Sun9:0013:00

<tbody>
</tbody>


Start timeEnd timeTotal work hours
1/26/2015 12:372/2/2015 5:59???????????????????

<tbody>
</tbody>

I've been using some formula to calculate total work hours within two given dates but the work time was the same every day of week.

Also, could there be some column in spreadsheet where I can input list of holidays so a formula excludes those listed days from calculations?

Thanks in advance for help!
 
That's a clever way to do it, I was going to suggest using a COUNTIF to determine whether start or end dates are in the holiday range, e.g.

=SUMPRODUCT(NETWORKDAYS.INTL(A2,B2,SUBSTITUTE("1111111",1,0,{1;2;3;4;5;6;7}),J$2:J$10),H$2:H$8)-IF(COUNTIF(J$2:J$10,INT(A2)),0,MEDIAN(VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,2,0),VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,3,0),MOD(A2,1))-VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,2,0))-IF(COUNTIF(J$2:J$10,INT(B2)),0,VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,3,0)-MEDIAN(VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,2,0),VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,3,0),MOD(B2,1)))

That should get the same results as your version
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This is solid base now, my next task is to apply this kind of counter for working hours for different objects which have different working schedules (on regular days, weekends, even on holidays). I've intended to make some kind of ID's which will pull working hours for particular object for every situation. I would never make it without your formula. Many thanks once again!
 
Upvote 0
That's a clever way to do it, I was going to suggest using a COUNTIF to determine whether start or end dates are in the holiday range...

I've gone a little bit further with the formula and now I'm trying to include special work time on holidays:

=SUMPRODUCT(NETWORKDAYS.INTL(A2,B2,SUBSTITUTE("1111111",1,0,{1;2;3;4;5;6;7}),J$2:J$10),H$2:H$8)+IFERROR(VLOOKUP(INT(A2),J:M,3,FALSE)-MEDIAN(VLOOKUP(INT(A2),J:M,2,FALSE),VLOOKUP(INT(A2),J:M,3,FALSE),MOD(A2,1)),-MEDIAN(VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,2,0),VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,3,0),MOD(A2,1))+VLOOKUP(TEXT(A2,"dddd"),E$2:H$8,2,0))+IFERROR(MEDIAN(VLOOKUP(INT(B2),J:M,2,FALSE),VLOOKUP(INT(B2),J:M,3,FALSE),MOD(B2,1))-VLOOKUP(INT(B2),J:M,2,FALSE),-VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,3,0)+MEDIAN(VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,2,0),VLOOKUP(TEXT(B2,"dddd"),E$2:H$8,3,0),MOD(B2,1)))

where J:M contains Holiday date as first column and other three columns are the same like for the area E:H (start, finish and duration columns).

Now this formula was written in cases where Holidays fall on the first and/or last day of the period but I'm trying to find way so the formula works even when Holidays are in between starting and ending date. Could you spare some time and assist me on this matter please? :)
 
Upvote 0
Subtracting COUNTIFS(J:J,">"&INT(A2),J:J,"<"&INT(B2)) multiplied by number of working hours for Holidays might do the job after all.
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,919
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top