How to get a total time between events


#1

1) Give a description of the problem
I’m trying to figure out how to get a value for the amount of time that has passed between two events. In my case door unlock and lock

2) What is the expected behavior?
I’d like to know how long it has been from the time a door us unlocked to the time it gets locked again. Although the logic could be used for pretty much anything, I guess. How long did I leave the window open, how long was a light on, How long was the TV on, etc

I’ve managed to get a time stamp to a variable, but don’t know how to convert the numbers to something like
3 hours and 15 minutes. For this example I will be sending myself a text message when the door is locked of how long it was unlocked.


#2

I answered my own question. Should have read before posting. For others in the future though.

I used an expression with formatDuration(Time1-Time2,true,‘m’)

the output from that was “3 minutes” if the time had been 3 minutes


#3

Just to clarify that should be formatDuration(Time1-Time2,true,‘m’)


#4

Thanks, I fixed the typo.


#5

What if the time is between two days?

I used $now to capture the start date and time of an event and the same for the end time of and event putting both values in a time variable. Then I used the following formula:

formatDuration(chargestop - chargestart, true, ‘m’)

The issue is if the event ends the next day then the calculation is off…So I changed the variable to a datetime variable but the formula no longer works…

Any thoughts on how to calculate duration between days and leaving the results in hours:minutes?

Thanks.