cancel
Showing results for 
Search instead for 
Did you mean: 

crystal reports formula for Difference between two time fields in HH:MM:SS format

former_member319241
Participant
0 Kudos
3,441

Hi,

I have two fields

In Time    :  10:45:20

Out Time :  18:48:20

Difference : 8 hours 3 minutes

So what will be the formula to calculate the difference?

The In Time and Out Time fields are in string format.

Thanks.

View Entire Topic
abhilash_kumar
Active Contributor

Hi Saurabh,

Since this is a string field, here's what you need to do:

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

NumberVar Hours   := Truncate ( TotalSec / 3600);

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

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

-Abhilash

GSG
Participant
0 Kudos

Hello Abhilash,

I used your formula and it works great but when In Time is lesser than Out Time, the values show like 23 hrs (something), I believe it considers the next day. Wondering how to fix it? Thx

JWiseman
Active Contributor
0 Kudos

hi Gurpreet Goraya, you should create a new question as this particular one has been answered already...and is quite old. In the new question though please include the formula syntax that you are using, show the current output on your report, and also indicate what you think the output should be, and why. Regards, -jamie