Skip to Content

Convert time to number, calc summary off formula in group

In Crystal Reports we have a formula that gives us hh:mm from a datetime field. We need to now get a summary off this formula in the group footer. However crystal does not allow us to do that natively when right clicking the formula. I have attempted to convert that formula to a number but it throws an error on everything I try. For instance tonumber or totext it will tell me it expects a date field, then it will tell me it expects a time field. All I am after would be a summary to add the hours and minutes for the group it is in.

report.png (131.0 kB)
report2.png (127.3 kB)
reports3.png (34.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 06, 2016 at 08:01 AM

    Hi Jeff,

    1. Create a formula called @Itr with this code and place it on the Details:

    EvaluateAfter({@DateDiff});
    shared numbervar fin_t;
    If {@DateDiff} >= time(00,00,00) or {@DateDiff} <= time(00,00,00) then
    (
    local timevar t := time({time_field});
    fin_t := fin_t + (hour(t)*3600) + (minute(t)*60) + second(t);
    )

    2. Create a formula called @Display with this code and place it on the Group Footer:

    shared numbervar fin_t;
    NumberVar Hours := Truncate (fin_t/3600);
    NumberVar Minutes := Truncate (Remainder (fin_t,3600)/60);
    Totext (Hours,0,"") + ':'+ Totext (Minutes,0,"")


    3. Create a formula called @Reset and place this on the Group Header #1:

    shared numbervar fin_t := 0;

    -Abhilash

    Add comment
    10|10000 characters needed characters exceeded