Time Difference in hh:mm:ss format

This snippet is to find difference between 2 times and expressed in hh:mm:ss format.

Example
StartingTime EndingTime Difference
09:00:00 05:00:30 08:30:00


Step 1 :Formula Editor -timeinseconds



DateDiff ("s",CDateTime({ATTENDANCE.TimeIn},CDateTime({ATTENDANCE.TimeIn}))



Step 2: Formula Editor – tdifference



local numbervar RemainingSeconds;
local numbervar Hours ;
local numbervar Minutes;
local numbervar Seconds;
//divide the @timeinseconds by 3600 to calculate hours. Use truncate to remove the decimal portion.
Hours := truncate({@timeinseconds} / 3600);
// Subtract the hours portion to get RemainingSeconds
RemainingSeconds := {@timeinseconds} - (Hours * 3600);
// Divide RemainingSeconds by 60 to get minutes. Use truncate to remove the decimal portion.
Minutes := truncate(RemainingSeconds/60);
// Subtract the Hours and Minutes and what is left
// over is seconds.
Seconds := {@ timeinseconds} - (Hours * 3600) - (Minutes * 60);
// Format the hours, minutes, and seconds to hh:mm:ss
totext(Hours,"00") + ":" + totext(Minutes,"00") + ":" + totext(Seconds,"00")





if you want to find total difference by each employee ,replace the hour and minute line with the following code



Hours := truncate(Sum ({@timeinseconds }, {Employee_Master.FirstName}) / 3600);
Seconds := Sum({@timeinseconds }, {Employee_Master.FirstName}) - (Hours * 3600) - (Minutes * 60);




Hope this code will help you...


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: