Complex Time/Date Difference Calculation?

I need to do a fairly complex time/date calculation on between certain hours. I have searched the forum but cannot see the solution I need.

Basically I need to calculate how long in hours a task takes with certain rules:

Business Hours are defined from 9pm on a Sunday to 9pm on a Friday;

Therefore if a task is created between Friday 9pm-Sunday 9pm the calculation of response time starts only from the 9pm on Sunday;

If a task response time falls between these times that time period is not included e.g. task comes in 8pm Friday and is completed 10pm Sunday. The total response time is 2 hours;

Further complicated that the Start and/or End time could span different time zones.

@BusinessDays may have been an option but this excludes full days which (I think) rules it out.

I appreciate there are many such questions relating to time/date issues but I have not found anything here that would suggest a way of doing this. Any suggestions?

Many thanks.

Subject: Complex Time/Date Difference Calculation?

The problem is that you’re basing the calculations on 9PM Sunday to 9PM Friday. If you start by adjusting the start and end times forward 3 hours in your formula or script, you are left with the much simpler task of calculating things based on midnight (start of day) Monday to midnight (start of day) Saturday (which is also end of day on Friday).

taskStart := @Adjust(StartDateTime; 0; 0; 0; 3; 0; 0);

taskEnd := @Adjust(EndDateTime; 0; 0; 0; 3; 0; 0);

There is a chance that the “start time” could fall into the forbidden zone if you start counting from the time a job arrives. You’d need to bump the start time forward to first thing Monday morning if it falls on a Saturday or Sunday after being adjusted:

@If(@Weekday(taskStart) = 1:7; @Set(“taskStart”; @TimeMerge(@Adjust(@Date(taskStart); 0; 0; @Select(@Weekday(taskStart); 1; 0; 0; 0; 0; 0; 2); 0; 0; 0); @Time(0; 0; 0)); “”);

The end of the task should always fall inside business hours, so you shouldn’t need to adjust it.

You can use @BusinessDays in a perverse kind of way to figure out how many days on this adjusted scale AREN’T being counted.

noWorkDays := @BusinessDays(taskStart; taskEnd; 2:3:4:5:6);

noWorkSeconds := noWorkDays * 86400;

taskSeconds := (taskEnd - taskStart) - noWorkSeconds;

Then it’s a matter of formatting the time-to-complete the way you want it.

That’s fairly simple – until you factor in time zones. If the task proper is being shunted around the globe, there’s going to be computational hell to pay. If the task is geographically static (that is, all of the work on task is happening in the same time zone), then you should be able to ignore the difference between the submitter’s time zone and the time zone in which the task is being carried out – the adjustment at the beginning of the formula will make up for the difference if the task is “started” while the people doing the work are off for the weekend.

Subject: RE: Complex Time/Date Difference Calculation?

Hi Stan,

This looks very close to something we are working on in on eof our systems. Very similar requirement but we would want to do our calculations based on a start time of 6am on a Monday with an end time of 9am Saturday. Is this a case of just adjusting the original dates in your formula?

Thanks for any feedback - I appreciate it’s a year or so since you answered the original question!