cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report Calculate differance between two time in HH:MM:SS Format

Former Member
0 Kudos

hi,

I have two fields

      

SR.NOIN TIMEOUT TIMEDIFF HRS
1   10:20:3120:10:10    ?
2    08:20:2018:10:20?
Total

i want to calculate time between this 2 time (In Time & Out Time)  in crystal report level.

please reply me fast !!!!

Thanks !!!!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Local NumberVar DaysDiff;

Local NumberVar HoursDiff;

Local NumberVar MinutesDiff;

Local NumberVar SecondsDiff;

Local StringVar strOut;

SecondsDiff := DateDiff('s',{table.InTime},{table.OutTime});

DaysDiff := SecondsDiff  \ (24 * 60 * 60);

SecondsDiff  := SecondsDiff  MOD (24 * 60 * 60);

HoursDiff:= SecondsDiff  \ (60 * 60);

SecondsDiff  := SecondsDiff  MOD (60 * 60);

MinutesDiff:= SecondsDiff  \ (60);

SecondsDiff  := SecondsDiff  MOD (60);

If DaysDiff  > 0 then

    strOut := CStr(DaysDiff ,0) & ' days ';

strOut := strOut & CStr(HoursDiff,0) & '.' & CStr(MinutesDiff,'00')  & '.' & CStr(SecondsDiff  ,'00') ;

strOut

abhilash_kumar
Active Contributor
0 Kudos

Hi Ashwini,

Assuming these fields are 'time' and you wish to display the difference in HH:MM format, try this:

NumberVar TotalSec :=  {@In Time} - {@Out Time};

NumberVar Hours   := Truncate ( TotalSec / 3600);

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

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

-Abhilash