# Calculate Time with "plus x min" and "minus x min"

**URL:** <https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851>\
**Category:** General\
**Created:** [24 February 2024 09:52 UTC](https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851 "2024-02-24T09:52:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2024 09:52 UTC](https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851/1 "2024-02-24T09:52:30Z")

</div>

Hi there,

is there a possibility to calculate time in NodeRed comparable to what I can do in SQL with dateadd (min) ?  
I have a time as a varchar ("23:59") and want to add one minute plus or minus - whenever I press a specific "+" or "-" button.

And I want it to jump automatically from 23:59 to 00:00

Is that possible ?

BG  
Gawan

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 February 2024 11:52 UTC](https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851/2 "2024-02-24T11:52:29Z")

</div>

you should be able to use $moment in a change node using JSONata  
e.g.

`$moment($$.payload, "HH:mm").add(7, 'minutes').format("HH:mm")`  
All string and numeric inputs can be msg.properties. This can be done in a function node to.

More examples [Search results for 'moment().add' - Node-RED Forum](https://discourse.nodered.org/search?q=moment().add)  
[Add - momentjs.com](https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/01-add/)

You can also use Javascript date objects and setMinutes [Date - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [24 February 2024 12:31 UTC](https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851/3 "2024-02-24T12:31:53Z")

</div>

To do this in the front-end (if you needed to), you can use the JavaScript `Date` object.

> **[Date - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)**
>
> JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects encapsulate an integral number that represents milliseconds since the midnight at the beginning of January 1, 1970, UTC (the epoch).

It has the basic functions to convert.

Of course, you could also simply use an input box set to time input which will constrain input automatically to valid times.

> **[\- HTML: HyperText Markup Language | MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time)**
>
> elements of type time create input fields designed to let the user easily enter a time (hours and minutes, and optionally seconds).

---

<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:** [24 May 2024 12:32 UTC](https://discourse.nodered.org/t/calculate-time-with-plus-x-min-and-minus-x-min/85851/4 "2024-05-24T12:32:37Z")

</div>

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