Find how much time has passed between timestamps with this function. The resut can be displayed in five different formats - seconds, minutes, hours, days and string. String puts all the numbers together with the words days, hours, minutes and seconds.
ElapsedTime (tStampBegin;tStampEnd;format)
// Input must be TimeStamp fields not strings. Format is a string
Let ( [
ElapsedSeconds = tStampEnd - tStampBegin ;
Days = Int ( ElapsedSeconds / 86400 ) ;
Hours = Int ( ( ElapsedSeconds - ( Days*86400 ) ) / 3600 ) ;
Minutes = Int ( ( ElapsedSeconds - ( ( Days * 86400 ) + ( Hours * 3600 ) ) ) / 60 );
Seconds = Int ( ElapsedSeconds - ( ( Days * 86400 ) + ( Hours * 3600 ) + (Minutes * 60 ) ) ) ;
ElapsedDays = ElapsedSeconds / 86400 ;
ElapsedHours = ElapsedSeconds / 3600 ;
ElapsedMinutes = ElapsedSeconds / 60
] ;
Case (
format = "Seconds" ;
// Result is in number or time format
ElapsedSeconds ;
format = "Minutes" ;
// Result is a string
ElapsedMinutes & " minutes" ;
format = "Hours" ;
// Result is a string
ElapsedHours & " hours" ;
format = "Days" ;
// Result is a string
ElapsedDays & " days" ;
format = "String" ;
// Result is a string
If ( Days = 1 ; Days & " day, " ; Days & " days, " ) & If ( Hours = 1 ; Hours & " hour, " ; Hours & " hours, " ) &
If ( Minutes = 1 ; Minutes & " minute, " ; Minutes & " minutes, " ) & If ( Seconds = 1 ; Seconds & " second. " ; Seconds & " seconds." )
)
)
