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

Covert minutes into hours in crystal reports 1

Status
Not open for further replies.

IB12013

IS-IT--Management
Jan 5, 2004
1
US
i am trying to convert total minutes into hours for example if i had 270 minutes i would like for it to read 4.30 hours any help would be appreciated.
 
Hi IB12013,
Try this, note that this will give 00.04.30 not 4.30 although those would be easy changes but this should give you a start:

numberVar TotalMinutes := 270; //I'm using your example of 270 minutes here

numberVar vhr := int(TotalMinutes/3600);
numberVar vrem := remainder(TotalMinutes,3600);

numberVar vmin := int(vrem/60);
vrem := remainder(vrem,60);

numberVar vsec := int(vrem);

stringVar dot := ".";
stringVar vshr := IIF(vhr<10,&quot;0&quot;+ToText(vhr,0),ToText(vhr,0));
stringVar vsmin := IIF(vmin<10,&quot;0&quot;+ToText(vmin,0),ToText(vmin,0));
stringVar vssec := IIF(vsec<10,&quot;0&quot;+ToText(vsec,0),ToText(vsec,0));
stringVar timestring := vshr+dot+vsmin+dot+vssec;
 
Try this:
Code:
NumberVar minutes := 270;

int(minutes/60) + 
((minutes/60 - int(minutes/60)) * .6)
I tried to simplify it using the MOD function, but it was giving me 'fuzzy numbers'.

-dave
 
this will work to:

Local NumberVar H;
Local NumberVar M;
Local stringvar HM;


H:= fieldname / 60 - .4; //prevents rounding
M:= fieldname mod 60 - .4;//prevents rounding


if M > 10
then
HM:=totext(H,0)+':'+totext(M,0)
else
//adds preceeding 0 for minutes less than 10
HM:=totext(H,0)+':'+(totext(0,0)+totext(M,0));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top