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

Formula problems converting minutes to days/hours/minutes 1

Status
Not open for further replies.

DLTaylor

MIS
Dec 17, 2003
51
GB
Crystal 7.0:

I am trying to convert a figure in minutes so it will display as days/hours/minutes.

I am using the following formula:

NumberVar ReqHours;
NumberVar ReqMinutes;
NumberVar ReqDays;
ReqDays:={Calls.ClosedMN}/480;
ReqDays:=Truncate(ReqDays);
ReqHours:=({Calls.ClosedMN}/60)-(ReqDays*480);
ReqHours:=Truncate(ReqHours);

if ReqHours<0 Then (ReqHours:=({Calls.ClosedMN}/60);
ReqHours:=Truncate(ReqHours);
ReqHours:=ReqHours-(ReqDays*8);
ReqHours:=Truncate(ReqHours) ) Else

ReqMinutes:={Calls.ClosedMN}-(ReqHours*60);
ToText(ReqDays,0)+&quot; Days &quot;+ToText(ReqHours,0)+&quot; Hours &quot;+ToText(ReqMinutes,0)+&quot; Minutes&quot;

(This is based on an 8 hour working day)

This formula works fine for converting into minutes only, or hours and minutes, but as soon as it needs to include days - the figures are distorted. I have put a sample of the data below.

Minutes = 222 displayed as 0 days, 3 hours, 42 minutes

This is ok.

Minutes = 999 displayed as 2 days, 0 hours, 41 minutes

This is incorrect.

Also, any records below the entry which includes days all show 41 minutes.

Any help would be appreciated.

 
I derived this from an FAQ written by synapsevampire. It should solve your problem.

@Display
Code:
numberVar dur := 999; //replace the 999 with your field.
numberVar days;
numberVar hrs;
numberVar min;
stringVar result;

days := Truncate(dur/480);
hrs := Truncate(Remainder(dur,480)/60);
min := Remainder(Remainder(Remainder(dur,480),60),60);


result := totext(days, &quot;0&quot;) + &quot; day(s), &quot; + totext(hrs, &quot;0&quot;) + &quot; hour(s), &quot; + totext(min,&quot;0&quot;) + &quot; minute(s)&quot;;

result

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top