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!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi and welcome to the board :)

Does this work for you?


Excel 2012
ABCDE
1Start TimeFinish TimeTotal Work HoursHolidays
2Mon 26-Jan-15 12.37 PMMon 2-Feb-15 05.59 PM4827-Jan-15
303-Feb-15
Sum
Cell Formulas
RangeFormula
C2=(NETWORKDAYS.INTL(A2, B2, "0000011",$E$2:$E$3 )*8)+(NETWORKDAYS.INTL(A2, B2, "1111100", $E$2:$E$3)*4)


/AJ
 
Upvote 0
Hi and thanks for quick reply!

When I've tried your formula in this exact example, I've got 52 hours as a result (I did not input any day as holiday). When I calculated manually, there is 3:23 work time on Monday, there are 4 full work days (Tuesday through Friday), and 4 hours each day of weekend between two given dates. That should total 43:23 of work time...

I don't see how given formula includes time of the start/end day in the calculation (which is very needed in this case).
 
Upvote 0
Oh sorry, I have forgotten to mention it. I'm using MS Excel 2010 at work and Office 2013 at home.
 
Upvote 0
OK, here's one way to calculate the hours.....

Construct a 4 column Table like this in E2:H8

Day
StartFinishDuration
Monday8:0016:008:00
Tuesday8:0016:008:00
Wednesday8:0016:008:00
Thursday8:0016:008:00
Friday8:0016:008:00
Saturday9:0013:004:00
Sunday9:0013:004:00

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

Now assuming start time/date in A2 and end time/date in B2 you can use this formula in C2

=SUMPRODUCT(NETWORKDAYS.INTL(A2,B2,SUBSTITUTE("1111111",1,0,{1;2;3;4;5;6;7}),J$2:J$10),H$2:H$8)-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)-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 J2:J10 contains a list of holiday dates

Format C2 to show "elapsed hours", i.e. with custom format [h]:mm

Note: I'm assuming that your start or end dates won't be on holidays - if they might be then you need an additional tweak to the formula
 
Upvote 0
I don't have time to check the formula now but the thing is that the start and end date could be on holidays as well so I could use your help on that too if you have time :)

Btw should this formula be working on any date range (no matter if it is 2 days or 55 days)? Because the events that I'm trying to track might last longer than one week.

Thanks in advance!
 
Upvote 0
Yes, it will work for any start and end dates/times as long as B2 >= A2

I'll look at amending for the possibility of start/end on holiday dates......
 
Upvote 0
Many thanks for your efforts :)

By the way, you don't need to waste your precious time to explain me that thoroughly. I consider that I've learned a lot about excel (most of the thanks to sites like MrExcel) so I think that I'm pretty adroit in Excel :) I usually don't use any formula before I have full understanding of the way it works.

The only field which I am totally clueless about is OLAP and direct connection to databases but I didn't need to use it yet.
 
Upvote 0
Update:

I think I've managed to bypass the problem! On your suggested formula I have added patch which worked on examples where starting or ending date matches holiday.

Formula which worked is:

=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:K,2,FALSE),-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(VLOOKUP(INT(B2),J:K,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)))

I've put bold+underline to the changes which were made in order to make formula work with any date entered as start/end point.
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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