How to subtract two time variables to get seconds

Can I use a DATE/TIME block to subtract two times, the results being the number of seconds between the times? How?

I can do this with a FUNCTION node:

var lstDate = new Date(payload.working.LastStartTime)
var nowFDate = new Date(payload.time);
payload.currentCycleTime = (nowFDate - lstDate) / 1000; // Convert to seconds

Where this is the payload:

I’ve tried it with a DATE/TIME block but I only see the number of seconds in the time of day sent through.

Hey @Bryan_Chase,

Yes you can find the difference between two time stamps using the Date/Time node. You want to use the logical function Diff that is included in this nodes configuration options in the Operation drop down.

This function returns the difference in milliseconds between the source date and the date provided.

Set your Path of Date to Compare to working.LastStartTime payload path.

Let us know if this solves your issue.


Diff produces units of milliseconds. That works, but how would I get seconds?


I would use the Math node and divide the milliseconds by 1000 to perform the conversion to seconds.