Return Hour and mins between two millis values

If a guy had the two following component props value how could he return the time between the two? As “hh:mm:ss” . Through scripting or expressions. All the functions and expressions return whole values. and when I end up trying to do math I get wrong hours.

timeE:1,572,425,661,000
timeS:1,572,420,540,000

timeE - timeS – should return : 01:25:07… I think or 1:25:21

dateFormat(({this.custom.newlot.timeE}-{this.custom.newlot.timeS}), "hh:mm:ss")

returns 07:25:21

How come?

I know almost nothing about java.text.SimpleDateFormat

timeS = 10/30/2019 02:47:54
timeE = 10/30/2019 04:13:18

dateFormat(
	fromMillis(
		{this.custom.newlot.timeE} - {this.custom.newlot.timeS}
	), "HH:mm:ss"
)

Something like this should work.

Reference:
https://docs.inductiveautomation.com/display/DOC80/dateDiff
https://docs.inductiveautomation.com/display/DOC80/*Between
https://docs.inductiveautomation.com/display/DOC80/dateFormat

dateFormat(fromMillis({this.custom.newlot.timeE} - {this.custom.newlot.timeS}), 
"hh:mm:ss")

returns 07:55:46

dateFormat(fromMillis({this.custom.newlot.timeE} - {this.custom.newlot.timeS}),
 "HH:mm:ss")

returns 19:55:46

with:

timeS:1,572,508,427,000  (10/31/2019 02:53:47)
timeE:1,572,515,373,000  (10/31/2019 04:49:33)

Could locale be causing an issue?

Your formats don’t match. :wink:

Any use of a delta between timestamps will have to be translated to hms in UTC, since deltas have no time zone. Consider just using modulus to pick off the components.

1 Like

Ohhh that makes sense… And I am -6 hours different than utc… That explains 07:55:46

Where at?

Sorry, that was a misread on my part.

Lol