Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

PDF exPLODE

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')