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

Seconds to a real amount of time 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
I'm using crystal 9 with a mysql database. The data is in seconds and I need it as follows:

days and hours - if it is 1 day and over (examples: 1 day; 1 day 5 hours; 2 days 10 hours)

hours, minutes and seconds - if it is 1 hour and over (examples: 5 hours 10 minutes; 10 hours)

minutes and seconds - if it is under 1 hour (examples: 3 minutes 5 seconds; 10 minutes)

Table

Value
208239
190
1457
179295

Help is appreciated.
 

Give this a try - if it all checks out then you would probably want to compile it as a custom function.

Code:
whileprintingrecords;
numbervar days := 0;
numbervar hours := 0;
numbervar minutes := 0;
numbervar seconds := 0;
stringvar dayslabel := "";
stringvar hourslabel := "";
stringvar minuteslabel := "";
stringvar secondslabel := "";

stringvar display := "";

if {SecondsField} >= 86400 then
(days := floor({SecondsField}/86400);
hours := floor(({SecondsField} mod 86400)/3600);
if days > 1 then dayslabel := " Days and " else dayslabel := " Day and ";
if hours > 1 then hourslabel := " Hours." else hourslabel := " Hour.";
display := totext(days,"#",0) + dayslabel + totext(hours,"#",0) + hourslabel;
if hours = 0 and days > 1 then display := totext(days,"#",0) + " Days."
else if hours = 0 then display := totext(days,"#",0) + " Day."
else display;)

else if {Sheet1_.Value} >= 3600 then
(hours := floor({SecondsField}/3600);
minutes := floor(({SecondsField} mod 3600)/60);
if hours > 1 then hourslabel := " Hours and " else hourslabel := " Hour and ";
if minutes > 1 then minuteslabel := " Minutes." else minuteslabel := " Minute.";
display := totext(hours,"#",0) + hourslabel + totext(minutes,"#",0) + minuteslabel;
if minutes = 0 and hours > 1 then display := totext(hours,"#",0) + " Hours."
else if minutes = 0 then display := totext(hours,"#",0) + " Hour."
else display;)

else 
(minutes := floor({SecondsField}/60);
seconds := floor({SecondsField} mod 60);
if minutes > 1 then minuteslabel := " Minutes and " else minuteslabel := " Minute and ";
if seconds > 1 or seconds = 0 then secondslabel := " Seconds." else secondslabel := " Second.";
display := totext(minutes,"#",0) + minuteslabel + totext(seconds,"#",0) + secondslabel;
if seconds = 0 and minutes > 1 then display := totext(minutes,"#",0) + " Minutes." 
else if seconds = 0  then display := totext(minutes,"#",0) + "Minute."
else display;);

display

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top