Skip to content Skip to footer

Formula Logic for calculating the time between In Time and Out time

Formula widget code:

Description

This formula widget will return the “Time Duration” between “In Time & Out Time” in the format of “HH:MM:SS”

var reggie = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/;
var s = '00'
var m = '00'
var h = '00'
if(Date_In && Date_Out){
var InTime = reggie.exec(Date_In);
var OutTime = reggie.exec(Date_Out);
InDate = new Date(Date.UTC(InTime[1],InTime[2],InTime[3],InTime[4],InTime[5],0,0))
OutDate = new Date(Date.UTC(OutTime[1],OutTime[2],OutTime[3],OutTime[4],OutTime[5],0,0)) 
timeInMiliseconds = OutDate - InDate 
h = Math.floor(timeInMiliseconds/1000/60/60);
m = Math.floor((timeInMiliseconds/1000/60/60 - h)*60);
s = Math.floor(((timeInMiliseconds/1000/60/60 - h)*60 - m)*60); 
0 <= s && s < 10 ? s = '0'+s: s = s
0 <= m && m < 10 ? m = '0'+m: m = m
0 <= h && h < 10 ? h = '0'+h: h = h
}
var difference  = h+':'+m+':'+s

return difference+''

Was This Article Helpful?

0
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami