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

Debug help with time formula

Status
Not open for further replies.

Drakhan

Technical User
Jun 3, 2002
67
US
To All Crystal Experts:

Need some help please! The following formula I have is based on a forum post, which is pretty close to what I require, however, I just cannot seem to get it quite right. I did make some minor changes from the original post to suit my needs. Any help would be much appreciated, as I am not a very good programmer.

Here is the situation. I have a forumla that calculates the number of seconds, based on the total time. For example, my formula {@Session Time} might yield a numberic equal to 12720 (this is the number of seconds I would like to convert to hours, minutes, seconds). The end result I would like to see is 3 hours 32 minutes. However, this is what I am receiving: 3 hours 1,920 minutes (it is not converting to minutes...it is still in seconds). Here is the formula I am using:

------------- BEGIN HERE ----------------

Numbervar session_time_in_seconds:={@Session Time};

Stringvar hours_spent:='';
Stringvar minutes_spent:='';
Stringvar seconds_spent:='';
Stringvar time_spent:='';

If session_time_in_seconds>60*60 then
hours_spent:=totext(truncate(session_time_in_seconds/(60*60)),0)+' hour'+ if truncate(session_time_in_seconds/(60*60))>1 then 's ' else ' '
Else
hours_spent:='';

If session_time_in_seconds>60 then
If session_time_in_seconds>(60*60) then
minutes_spent:=totext(remainder((session_time_in_seconds),(60*60)),0)+' minute'+ if remainder((session_time_in_seconds),(60*60))>1 then 's ' else ' '
Else
minutes_spent:=totext(truncate((session_time_in_seconds)/(60)),0)+' minute'+ if truncate((session_time_in_seconds)/(60))>1 then 's' else ' '
Else
minutes_spent:='';

If session_time_in_seconds>60 then
seconds_spent:=totext(remainder(session_time_in_seconds,60),0)+' second'+ if remainder(session_time_in_seconds,60)>1 then 's' else ''
Else
seconds_spent:=totext(session_time_in_seconds,0)+' second'+ if session_time_in_seconds>1 then 's' else '';

Time_spent:=hours_spent+minutes_spent+seconds_spent

------------- END HERE -----------------

Any thoughts on how one can fix the minutes into seconds? I believe it just has to be divided by 60, but I am not sure where to or how to do this...thank you in advance.
 
Ok, I managed to fix it. Here is the formula:

START HERE

Numbervar session_time_in_seconds:={@Session Time};

Stringvar hours_spent:='';
Stringvar minutes_spent:='';
Stringvar seconds_spent:='';
Stringvar time_spent:='';

If session_time_in_seconds>3600 then
hours_spent:=totext(truncate(session_time_in_seconds/3600),0)+' hour'+ if truncate(session_time_in_seconds/3600)>1 then 's ' else ' '
Else
hours_spent:='';

If session_time_in_seconds>60 then
If session_time_in_seconds>3600 then
minutes_spent:=totext((remainder(session_time_in_seconds,3600))/60,0)+' minute'+ if ((remainder(session_time_in_seconds,3600))/60)>1 then 's ' else ' '
Else
minutes_spent:=totext(truncate(session_time_in_seconds/60),0)+' minute'+ if truncate(session_time_in_seconds/60)>1 then 's' else ' '
Else
minutes_spent:='';

If session_time_in_seconds>60 then
seconds_spent:=totext(remainder(session_time_in_seconds,60),0)+' second'+ if remainder(session_time_in_seconds,60)>1 then 's' else ''
Else
seconds_spent:=totext(session_time_in_seconds,0)+' second'+ if session_time_in_seconds>1 then 's' else '';

Time_spent:=hours_spent+minutes_spent

END HERE

This formula should covert your seconds formula into a proper hours, minutes, seconds format. To add 'seconds' to the print out, just add "+seconds_spent" to the end of the Time_spent equation at the bottom of the formula. The last equation should look like:

Time_spent:=hours_spent+minutes_spent+seconds_spent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top