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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation of Date/Time fields with business time

Status
Not open for further replies.

bar1515

Technical User
Dec 16, 2008
5
US
All,
I have 2 date/time fields in the following format: 11/10/2008 10:00:00 AM
I tried to use the following formula for the first part to convert as days: got this from
WhileReadingRecords;
Local DateVar Start := {HPD_Help_Desk.Submit_Date}; // place your Starting Date here
Local DateVar End := {HPD_Help_Desk.Last_Resolved_Date}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;
DateVar Array Holidays;

Weeks:= (Truncate (End - dayofWeek(End) + 1
- (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);

However when I try to save this formula it says "a date is required" and points to the Submit Date. This field is a date time field.
Any ideas on how i can calculate the business hours between 2 date_time fields?
Thanks for your help in advance.
Brandi
 
Local DateVar Start := Date({HPD_Help_Desk.Submit_Date}); // place your Starting Date here
Local DateVar End := date({HPD_Help_Desk.Last_Resolved_Date}); // place your Ending Date here

The above changes should fix it.

-LB
 
I have used this and it works like a charm.

WhilePrintingRecords;
NumberVar Days := {Your Working Days Field}; // The field that calculates your business days
TimeVar SetStart := TimeValue( "7:00"); // The start your work day
TimeVar SetEnd := TimeValue("16:00"); // The end your work day
TimeVar StartTime := TimeValue({Your Field1});// The data field that holds your Start Time
TimeVar EndTime := TimeValue({Your Field2}); // The data field that holds your End Time
//These lines are only needed if your times are strings that do not indicate AM or PM, like "3:30"
//They will convert afternoon times to PM. Of course, this won't work if your workday is over 12 hours.
If StartTime < (SetEnd - 43200) then StartTime := StartTime + 43200;
If EndTime < (SetEnd - 43200) then EndTime := EndTime + 43200;
Days * ((SetEnd - SetStart) / 3600)
- ((SetEnd - EndTime) / 3600)
- ((StartTime - SetStart) / 3600)
 
Thanks for the information.. I was trying to use this exact code but when it says TimeValue9{Your Field1}) my field is a date time field and is not seperated out into 2 fields. is there a way to partion the time out and then calculate that time? Thanks again for taking time to help me.
Brandi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top