[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Exclude, nights, weekends from date/time calculation

Posted on 2013-05-13
10
Medium Priority
?
1,465 Views
Last Modified: 2013-05-15
Hello,
 
I need to calculate the time difference between 2 date/time columns.  The challenge is that I need to exclude evenings (after 5 p.m.), weekends (Saturday, Sunday) and U.S. Bank holidays. Is there a formula that I can plug into my existing formula to do this?

Please see the attached file and thanks in advance for all of your help!
Book-1.xls
0
Comment
Question by:angelfromabove
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 23

Expert Comment

by:tailoreddigital
ID: 39163663
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39163907
Hi,

I need to calculate the time difference between 2 date/time columns.  The challenge is that I need to exclude evenings (after 5 p.m.), weekends (Saturday, Sunday) and U.S. Bank holidays. Is there a formula that I can plug into my existing formula to do this?

When does a morning "start" (if an evening commences at 5pm)?

BFN,

fp.
0
 

Author Comment

by:angelfromabove
ID: 39165375
Let's just say that morning starts at 7:30 a.m. for these purposes.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 500 total points
ID: 39165852
Try listing your holiday dates in H2:H10 then use this formula in row 2

=(NETWORKDAYS(A2,B2,H$2:H$10)-1)*("17:00"-"7:30")+IF(NETWORKDAYS(B2,B2,H$2:H$10),MEDIAN(MOD(B2,1),"7:30","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2,H$2:H$10)*MOD(A2,1),"7:30","17:00")

custom format as [h]:mm and copy down and you'll get the elapsed time in hours including just 07:30 to 17:00 on working days. Using that formula I get 766:01 for your last example

regards, barry
0
 

Author Comment

by:angelfromabove
ID: 39166771
Perfect, thank you!  Can I just ask one more thing?

If the time value in the 2nd column of cells is blank, in other words the task is still in progress, I am getting ###### (pound signs) as the returned value.  Is there any way to say that if that cell is blank, to return the string "still in progress"?

Thanks!
0
 
LVL 81

Assisted Solution

by:byundt
byundt earned 1500 total points
ID: 39166942
To trap a blank cell, just put barryhoudini's formula inside an IF statement:
=IF(B2="","still in progress",(NETWORKDAYS(A2,B2,H$2:H$10)-1)*("17:00"-"7:30")+IF(NETWORKDAYS(B2,B2,H$2:H$10),MEDIAN(MOD(B2,1),"7:30","17:00"),"17:00")-MEDIAN(NETWORKDAYS(A2,A2,H$2:H$10)*MOD(A2,1),"7:30","17:00"))
0
 

Author Comment

by:angelfromabove
ID: 39167059
Great byundt, it worked!
0
 

Author Comment

by:angelfromabove
ID: 39167065
Hi Barry, can you explain each component of the formula?

I will award the points and accept your solution shortly. I just want to make sure that I have a good understanding and I can explain it to someone..  For example, I don't know what Median and MOD are and what their function is in the formula?

Thanks!!!!
0
 
LVL 81

Assisted Solution

by:byundt
byundt earned 1500 total points
ID: 39167082
MOD(B2,1)      Divides B2 by 1, then returns the remainder (fractional part of the original number). Because time is the fractional part of a date/time serial number, MOD(B2,1) is a clever way of getting just the time part of B2.

MEDIAN picks the middlemost number in a set, so MEDIAN(MOD(B2,1),"7:30","17:00") would pick
7:30 if B2 is before 7:30
the actual time if B2 is between 7:30 and 17:00
17:00 if B2 is after 17:00

NETWORKDAYS returns the number of working days, from start through finish, but excluding weekends and holidays. If you start and finish on the same working day, then NETWORKDAYS returns 1, unless that day occurs on a weekend or holiday--in which case NETWORKDAYS returns 0.
NETWORKDAYS(A2,B2,H$2:H$10)-1)*("17:00"-"7:30")  is the number of working hours in those full workdays. You subtract 1 from NETWORKDAYS because you need to account for partial hours on start and finish days separately.

If B2 is on a weekend or holiday, then NETWORKDAYS(B2,B2,H$2:H$10) returns 0.
Likewise, if A2 is a weekend or holiday, then NETWORKDAYS(A2,A2,H$2:H$10) returns 0.
If either is a working day, then NETWORKDAYS returns 1.

IF(NETWORKDAYS(B2,B2,H$2:H$10),MEDIAN(MOD(B2,1),"7:30","17:00"),"17:00")
If B2 is a working day, then return MEDIAN(MOD(B2,1),"7:30","17:00"). Otherwise, return 17:00

MEDIAN(NETWORKDAYS(A2,A2,H$2:H$10)*MOD(A2,1),"7:30","17:00")
If A2 is a working day, then return MEDIAN(start time, 7:30, 17:00)
If A2 is not a working day, then MEDIAN(0, 7:30, 17:00) will return 7:30
0
 
LVL 81

Accepted Solution

by:
byundt earned 1500 total points
ID: 39167087
So if you put the three parts of the formula together:
Total number of working hours equals:
number of working hours assuming a full first day and ignoring the last day
plus working hours on last day until task ended
minus working hours on first day before task started

(NETWORKDAYS(A2,B2,H$2:H$10)-1)*("17:00"-"7:30")       number of working hours assuming a full first day and ignoring the final day

+IF(NETWORKDAYS(B2,B2,H$2:H$10),MEDIAN(MOD(B2,1),"7:30","17:00"),"17:00")    plus number of working hours on final day until task ended

-MEDIAN(NETWORKDAYS(A2,A2,H$2:H$10)*MOD(A2,1),"7:30","17:00"))   minus number of working hours on first day before task started
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question