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

seconds to Minutes/Seconds 1

Status
Not open for further replies.

TerriO

Technical User
Jan 9, 2002
84
US
I have a number field that I need to convert to minutes and seconds my field 127 need to convert to 2:07 I have tried many things, surely there is a simple answer??

Terri
 
In Crystal 8.5, you can
a) Divide second by 60, in a formula field
b) Truncate the answer to get minutes
c) Multiply the minutes by 60, and subtract from seconds. This gives you the spare seconds.

Do in formula fields. Something like
@Minutes
truncate({seconds}/60)
@Seconds
{seconds}-(60*@Minutes)
@MinSec
totext(@Minutes) & ":" & totext(@Seconds)


Madawc Williams
East Anglia, Great Britain
 
You can so this in one formula instead of three:

numbervar sec:={your.seconds.field};

stringvar mins;
stringvar secs;

mins:=totext(truncate(sec/60),"0");
secs:=totext(remainder(sec,60),"00");

mins +":" + secs


Mike
 
Thanks Mike, that worked and was quick and simple, seems there are so many different ways to do this for what would appear to be a simple conversion.. Your formula did the trick.. !!! ;)

Terri
 
One more thing, what about the total average for the same field..

Terri
 
You would do average first on the seconds field and then convert using the formula.



Mike
 
If you want to add Hrs into the mix you can use the following.

I built off of Mike's existing code, so as not to grab all the credit.

numbervar sec:={Sec value here};

numbervar nMins;
numbervar nSecs;
numbervar nHrs;
stringvar sMins;
stringvar sSecs;
stringvar sHrs;

nHrs:=truncate(sec/3600);
nMins:=truncate(sec/60) - nHrs * 60;
nSecs:=remainder(sec,60);

sHrs:=totext(nHrs,"00");
sMins:=totext(nMins,"00");
sSecs:=totext(nSecs,"00");


sHrs + ":" + sMins +":" + sSecs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top