# Duration in MM between two times

**URL:** <https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797>\
**Category:** General\
**Created:** [16 September 2022 11:11 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797 "2022-09-16T11:11:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![notownblues](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/notownblues/32/67810_2.png) [@notownblues](https://discourse.nodered.org/u/notownblues)\
**Post date:** [16 September 2022 11:11 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/1 "2022-09-16T11:11:38Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/017011e9af74dcf6e0a7c1e53a8bf2f74bc43168.png)

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [16 September 2022 11:29 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/2 "2022-09-16T11:29:02Z")

</div>

Have a look at [this](https://discourse.nodered.org/t/how-to-calculate-time-difference-between-two-timestamps/67550) topic.

---

<div class="post-metadata">

**Author:** ![notownblues](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/notownblues/32/67810_2.png) [@notownblues](https://discourse.nodered.org/u/notownblues)\
**Post date:** [16 September 2022 11:38 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/3 "2022-09-16T11:38:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [16 September 2022 12:04 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/4 "2022-09-16T12:04:38Z")

</div>

Here you go:  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d7657260c984cfa837442d90336c886436c6fc6.png)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![notownblues](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/notownblues/32/67810_2.png) [@notownblues](https://discourse.nodered.org/u/notownblues)\
**Post date:** [16 September 2022 12:05 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/5 "2022-09-16T12:05:39Z")

</div>

Thank you so much @edje11!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 September 2022 12:06 UTC](https://discourse.nodered.org/t/duration-in-mm-between-two-times/67797/6 "2022-09-30T12:06:39Z")

</div>

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