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

Rounding Time to Minutes

Status
Not open for further replies.

ncheek

MIS
Sep 3, 2002
2
US
Hi:
I have a Time Card Report I created in Crystal 10. The database I am pulling from displays the hours in decimal time (ie, 1 hr 30 mins is displayed as 1.5). I used the following formula to convert decimal hours to hours/minutes/seconds (where 'regular_hr' field is the time displayed in decimal hours):

Whileprintingrecords;
numbervar DecTime:={regular_hr};
numberVar Totalsecs:=(DecTime*60)*60;
numberVar dur :=Totalsecs;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar hhmmss;

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

hhmmss :=totext(hrs, "0") + ":" + totext(min, "00") + ":" + totext(sec, "00");

hhmmss

This formula worked great. The problem I'm running into is that once I get the format in hrs/mins/sec I need to round the seconds to hrs/mins only. For example, if the time displays as 2:25:59, I want it to round to 2:26.

Since the field was converted to text, I cannot do this using the Date and Time tab on the Format Editor property sheet.

Any suggestions?

Thanks
 
Why not just change last bit of your formula

hrs :=Truncate(Truncate(dur/60)/60);
min :=Remainder(Truncate(dur/60),60);
if Remainder(dur,60) >= 30 then min:=min+1

hhmm :=totext(hrs, "0") + ":" + totext(min, "00")

Ian
 
Ian:
Thank you, that is exactly what I was looking for.
Appreciate your quick response.
Thanks again,
Nancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top