Comparing time difference in HH:mm:ss

Hi
I have 2 DateTime tags:
‘Before’, in the format of 2020-08-27 14:23:47
‘After’, in the format of 2020-08-28 03:10:05

I would need to display the time difference of After minus Before in ‘HH:mm:ss’ format.
I am currently using this script:
image

This script is working, but i would like to know if there is any smarter/shorter script to implement instead?

I have tried below second method as well:

In terms of complexity, i feel that using second method would be better.
But I am not sure in terms of “functions”, which would be more… efficient?

I don’t think what you’ve got will work; your calcs will give the wrong numbers.

For example, your After minute is 10 and your Before minute is 23. Ignoring hours and seconds, this is 47 minutes apart. Your calc will say 13.

If your difference will never be more than 24 Hours (and you don’t care about timezones…) you could do something like:

dateFormat(
     fromMillis({After}-{Before})
,"HH:mm:ss")

However - I would maintain would be much easier to do in a python script

Hi jonathan

Youre right… both my dates were 27th during the simulation, and hence i missed that out.
I have tried your script, but i dont think it is considering the difference between 27th and 28th as well…

It is, but as I said it doesn’t take into account multiple days, or even timezones -

So using your times above it says the time difference is 13 hours, 46 mins and 18 seconds where it should only be 12:46:18 - this is because in my country we are currently +1 hour against our normal UTC offset.

Python would be much better for this.

See this thread for discussion on how to do this in expressions or Python.