Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Business Hours Calculation/Nested If

Status
Not open for further replies.

Wabush

Programmer
Jan 15, 2001
31
0
0
US
Hi there,

I am making use of Ken Hamady's formula that calculates the number of business hours between two dates (see FAQ, Common Formula Examples) and it works great until we have the exception date-time that is outside of the normal business hours. Then it results in a negative time.

I have tried to customize Ken's formula to account for the times that are outside, but I get a syntax error.
Here is the formula;

if TimeValue({HD_INCIDENT.LOGGED_DT}) < TimeValue(&quot;7:30:00&quot;)
and TimeValue({HD_INCIDENT.ASSIGN_DT}) < TimeValue(&quot;17:00:00&quot;)
then
TimeVar SetStart := TimeValue({HD_INCIDENT.LOGGED_DT})
TimeVar SetEnd := TimeValue(&quot;17:00:00&quot;)
TimeVar StartTime := TimeValue({HD_INCIDENT.LOGGED_DT})
TimeVar EndTime := TimeValue({HD_INCIDENT.ASSIGN_DT})

else if TimeValue({HD_INCIDENT.LOGGED_DT}) >= TimeValue(&quot;7:30:00&quot;)
and TimeValue({HD_INCIDENT.ASSIGN_DT}) >= TimeValue(&quot;17:00:00&quot;)
then
TimeVar SetStart := TimeValue(&quot;7:30:00&quot;)
TimeVar SetEnd := TimeValue({HD_INCIDENT.ASSIGN_DT})
TimeVar StartTime := TimeValue({HD_INCIDENT.LOGGED_DT})
TimeVar EndTime := TimeValue({HD_INCIDENT.ASSIGN_DT})

else if TimeValue({HD_INCIDENT.LOGGED_DT}) < TimeValue(&quot;7:30:00&quot;)
and TimeValue({HD_INCIDENT.ASSIGN_DT}) >= TimeValue(&quot;17:00:00&quot;)

TimeVar SetStart := TimeValue({HD_INCIDENT.LOGGED_DT})
TimeVar SetEnd := TimeValue({HD_INCIDENT.ASSIGN_DT})
TimeVar StartTime := TimeValue({HD_INCIDENT.LOGGED_DT})
TimeVar EndTime := TimeValue({HD_INCIDENT.ASSIGN_DT})

numberVar HoursElapsed:=
Days * ((SetEnd - SetStart) / 3600)
- ((SetEnd - EndTime) / 3600)
- ((StartTime - SetStart) / 3600);

I'm confused about the semi-colon placement in the nested if statements...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top