phone: (540)338-0194
email: ken@kenhamady.com

´╗┐

 Crystal Reports formula examples

Converting total seconds to a formatted "elapsed time" string:

When you need to display an elapsed time in the format of DD:HH:MM:SS, you can convert the time value to a total seconds number and use the following formula to convert the seconds total to a formatted string.    All you need to do is replace the dummy field on the end of the second line with your net seconds or total seconds field.  I am using WhilePrintingRecords but you can use WhileReadingRecords in cases where the {YourTable.TotalSeconds} field does not involve a Crystal Summary operation like Sum() or Average().
 
WhilePrintingRecords;
NumberVar TotalSec :=  {YourTable.TotalSeconds};

NumberVar Days    := Truncate  (TotalSec / 86400);
NumberVar Hours   := Truncate  (Remainder ( TotalSec , 86400) / 3600) ;
NumberVar Minutes := Truncate  (Remainder ( TotalSec , 3600) / 60) ;
NumberVar Seconds := Remainder (TotalSec , 60) ;

Totext ( Days ,    '##' ) +  ':' +
Totext ( Hours ,   '00' ) +  ':' +
Totext ( Minutes , '00' ) +  ':' +
Totext ( Seconds , '00' )


If you want to display only in hours and minutes you should use this version:

WhilePrintingRecords;
NumberVar TotalSec :=  
{YourTable.TotalSeconds};

NumberVar Hours   := Truncate ( TotalSec / 3600);
NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60);

Totext ( Hours,  '####') + ':'+
Totext ( Minutes,'00')