Time spent calculation: exclude non-business hours and weekends

ebrandonwhite

New Member
Joined
Jun 11, 2010
Messages
6
Thanks in advance for any help that can be offered.

I am using Excel 2007.

Variables:
StartDT = The time the ticket came into the system
EndDT = The time the agent closed the ticket
StartTime = The time the business day starts
StopTime = The time the business day ends
TimeSpent = The calculated time spent

Business hours are 0600 - 1800.

Weekends and after hours are not included in time spent.

ex.
StartDT
4/9/2010 17:00

EndDT
4/12/2010 7:00

Scenario: A case comes in at 17:00 on Friday 4/9/2010. The case is closed at 07:00 on Monday 4/12/2010. Total time spent (calculated manually) is 2 hours.

So the columns would look like:

|StartDT|EndDT|StartTime|StopTime|TimeSpent|


So what I need is a formula for the TimeSpent column that calculates the time spent using the given information in the previous columns.

Thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Assuming that StartDT and EndDT are always within business hours you can use this formula

=(NETWORKDAYS(StartDT,EndDT)-1)*(StopTime-StartTime)+MOD(EndDT,1)-MOD(StartDT,1)

format result cell as [h]:mm
 
Upvote 0
Assuming that StartDT and EndDT are always within business hours you can use this formula

=(NETWORKDAYS(StartDT,EndDT)-1)*(StopTime-StartTime)+MOD(EndDT,1)-MOD(StartDT,1)

format result cell as [h]:mm

Barry,
Unfortunately life isn't that easy. Customer can submit any time of any day so sometimes the start or end dates will land in the untracked hours.

Any ideas?

Thanks!

~Eric
 
Upvote 0
OK, Eric, in that case you can use this version

=(NETWORKDAYS(StartDT,EndDT)-1)*(StopTime-StartTime)+IF(NETWORKDAYS(EndDT,EndDT),MEDIAN(MOD(EndDT,1),StopTime,StartTime),StopTime)-MEDIAN(NETWORKDAYS(StartDT,StartDT)*MOD(StartDT,1),StopTime,StartTime)
 
Upvote 0
OK, Eric, in that case you can use this version

=(NETWORKDAYS(StartDT,EndDT)-1)*(StopTime-StartTime)+IF(NETWORKDAYS(EndDT,EndDT),MEDIAN(MOD(EndDT,1),StopTime,StartTime),StopTime)-MEDIAN(NETWORKDAYS(StartDT,StartDT)*MOD(StartDT,1),StopTime,StartTime)


Barry,
So that works perfectly! Thank you so much!

I only have one problem.

Time spent displays: 142183
But the actual value is: 4/7/1900 5:43:20 PM

How do I get the answer to be just 142183?

Thanks again!

~Eric
 
Upvote 0
Thanks Barry for the tip.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have a pretty similar scenario to the previous problem. We need to include another variance; holidays.<o:p></o:p>
<o:p></o:p>
For example the scenario below mentioned we had September 6th as holiday, so we need to substract that day:<o:p></o:p>
<o:p></o:p>
<TABLE class=MsoNormalTable style="WIDTH: 388pt; BORDER-COLLAPSE: collapse; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 0cm 0cm 0cm" cellSpacing=0 cellPadding=0 width=517 border=0><TBODY><TR style="HEIGHT: 15pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111>StartDT<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111>EndDT<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111>StartTime<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111>StopTime<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; WIDTH: 56pt; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=75>TimeSpent<o:p></o:p>
</TD></TR><TR style="HEIGHT: 15pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes"><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent">
03/09/2010 16:01<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent">
07/09/2010 11:01<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent">
08:00:00 a.m.<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent">
05:00:00 p.m.<o:p></o:p>
</TD><TD style="BORDER-RIGHT: #f0f0f0; PADDING-RIGHT: 0cm; BORDER-TOP: #f0f0f0; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: #f0f0f0; PADDING-TOP: 0cm; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent">
12:59<o:p></o:p>
</TD></TR></TBODY></TABLE>
<o:p></o:p>
The manual calculation should show 03:59 hours.<o:p></o:p>
<o:p></o:p>
Do you have any idea?<o:p></o:p>
<o:p></o:p>
Thanks in advance for your help.<o:p></o:p>
Best regards,<o:p></o:p>
Hector Diaz
 
Upvote 0
Hello HectorD, welcome to MrExcel

You can insert the holiday range into each NETWORKDAYS function, so if your start and end times will always be within business hours you can use

=(NETWORKDAYS(StartDT,EndDT,Holidays)-1)*(StopTime-StartTime)+MOD(EndDT,1)-MOD(StartDT,1)

or for any start and end times

=(NETWORKDAYS(StartDT,EndDT,Holidays)-1)*(StopTime-StartTime)+IF(NETWORKDAYS(EndDT,EndDT,Holidays),MEDIAN(MOD(EndDT,1),StopTime,StartTime),StopTime)-MEDIAN(NETWORKDAYS(StartDT,StartDT,Holidays)*MOD(StartDT,1),StopTime,StartTime)
 
Upvote 0
You are a genius!! Thank you!!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have tried, but I did not understood, who to add the holidays, so I added as a day and it worked, but what if there are a more than 1 holiday in the month? How should I write the holidays?
<o:p></o:p>
<TABLE style="WIDTH: 472pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=630 border=0><COLGROUP><COL style="WIDTH: 83pt; mso-width-source: userset; mso-width-alt: 4059" span=4 width=111><COL style="WIDTH: 65pt; mso-width-source: userset; mso-width-alt: 3145" width=86><COL style="WIDTH: 75pt; mso-width-source: userset; mso-width-alt: 3657" width=100><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111 height=20><TABLE style="WIDTH: 453pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=604 border=0><COLGROUP><COL style="WIDTH: 83pt; mso-width-source: userset; mso-width-alt: 4059" span=4 width=111><COL style="WIDTH: 65pt; mso-width-source: userset; mso-width-alt: 3145" width=86><COL style="WIDTH: 56pt; mso-width-source: userset; mso-width-alt: 2706" width=74><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=111 height=20>StartDT</TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111>EndDT</TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111>StartTime</TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111>StopTime</TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 65pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=86>Holiday</TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 56pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=74>TimeSpent</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl65 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" align=right height=20>03/09/2010 16:01</TD><TD class=xl65 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right>07/09/2010 11:01</TD><TD class=xl67 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right>08:00:00 a.m.</TD><TD class=xl67 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right>05:00:00 p.m.</TD><TD class=xl69 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right>06/09/2010</TD><TD class=xl70 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right>03:59</TD></TR></TBODY></TABLE></TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111></TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111></TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 83pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=111></TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 65pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=86></TD><TD style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; WIDTH: 75pt; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" width=100></TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" align=right height=20></TD><TD class=xl63 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right></TD><TD class=xl65 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right></TD><TD class=xl65 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right></TD><TD class=xl68 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right></TD><TD class=xl67 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; BORDER-LEFT: #f0f0f0; BORDER-BOTTOM: #f0f0f0; BACKGROUND-COLOR: transparent" align=right></TD></TR></TBODY></TABLE>
Thank you,

Best regards,
 
Upvote 0
Typically you would list all holidays for the year (or for the period that interests you, whether shorter or longer), one date per cell somewhere on the worksheet, you can then use that range directly in NETWORKDAYS function, e.g.

=NETWORKDAYS(A2,B2,H$1:H$10)

where H1:H10 contains the holiday dates.....or you can name that range holidays and then use

=NETWORKDAYS(A2,B2,holidays)
 
Upvote 0
I need to make a similar calculation as this one. The only difference is that I don't need to eliminate the weekends only hours from 3rd shift (10:30 PM to 6:00 AM)
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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