Duration in MM between two times

Hi,

I'm trying to write a function to give me the duration in minutes from two times in the same payload. For example 17:45 to 18:45 would give me a duration of 60min.

Do you guys know how I can achieve that?

Many thanks

Have a look at this topic.

Thanks for your suggestion @edje11.

I actually saw it earlier this morning and tried it but because mine isn't a timestamp and I have the HH:MM format I got stuck.

Here you go:
Capture

[{"id":"52c45c6e.1729a4","type":"function","z":"e39579ff.bf2ad","name":"","func":"var time1 = new Date(\"1970-01-01 \" + msg.payload.time1);\nvar time2 = new Date(\"1970-01-01 \" + msg.payload.time2);\nvar diff = time2-time1\n\nmsg.payload = (diff /1000)/60\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":320,"wires":[["cd141193.50c058"]]}]
2 Likes

Thank you so much @edje11!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.