Search code examples
timecrystal-reportsformula

Crystal Formula to sum time field in footer


I'm trying to add/sum up TIME and have it in TIME format HH:MM in the footer The field was a number field only showing by minutes (Example: 60.00) and created a formula to convert it to HHMM (01:00) by:

whileprintingrecords;
numberVar hrs;
numberVar min;
stringVar hhmm;
hrs := Remainder(Truncate({field.duration}/60),60);
min := Remainder({field.duration},60);
hhmm := totext(hrs,"00") + ":" + totext(min,"00"); 
hhmm

Now I need to add it in the footer but in format HH:MM any help is greatly appreciated.


Solution

  • I think you kind of answered your own question. Instead of doing that formula for each record's duration just do it for the sum of the durations.

    local numbervar sum_mins := sum([field.duration}); //sum up each record's duration in mins
    local numbervar hrs;
    local numbervar mins;
    hrs := truncate(sum_mins/60); //get whole hours
    mins := remainder(sum_mins,60); //get remaining minutes
    totext(hrs,'00') + ':' + totext(mins,'00')
    

    Then place this formula in the report's footer.