# Cron plus -1 hour

**URL:** <https://discourse.nodered.org/t/cron-plus-1-hour/53381>\
**Category:** General\
**Created:** [8 November 2021 13:59 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381 "2021-11-08T13:59:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [8 November 2021 13:59 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/1 "2021-11-08T13:59:08Z")

</div>

Hi! Is there a way to make my cron plus activate an output minus 1 h ?  
This is how it is set up:

```auto
[{"id":"e4f20e150336f746","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"872eb42d0fb54709","type":"cronplus","z":"e4f20e150336f746","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":546,"y":126,"wires":[[]]},{"id":"c2ed4f8861720be9","type":"function","z":"e4f20e150336f746","name":"Generate date event","func":"\n// create Dynamic Cron Schedule\nmsg.payload = {\n \"command\": \"add\",\n \"name\": \"Dynamic Cron Schedule\",\n \"expression\": new Date(msg.payload.totalMinimumStartsAt),\n \"expressionType\": \"dates\",\n \"payload\": \"ON\",\n \"payloadType\": \"str\",\n// \"limit\": 1 \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":334,"y":126,"wires":[["872eb42d0fb54709"]]}]

```

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [8 November 2021 14:03 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/2 "2021-11-08T14:03:06Z")

</div>

"Move" to another time zone??

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 November 2021 14:36 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/3 "2021-11-08T14:36:21Z")

</div>

In your Function node reference the [Moment js](https://momentjs.com/docs/#/manipulating/subtract/) library using the `functionExternalModules` option  
you can read how to set that up [here](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option)

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

and in code its easy to make datetime calculations ..

```javascript
var time = moment.duration("01:00:00"); // time to subtract
var date = moment("2014-06-07 09:22:06");
node.warn(date);

msg.payload = date.subtract(time);

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [8 November 2021 15:14 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/4 "2021-11-08T15:14:27Z")

</div>

I can't really test because I don't know what your input is into the function node (its good practice to add an inject node with a sample of data to help with testing).  
It's usually achieved in solar events by adding `offset: "-60"` to the dynamic object, but it may not work with cron events. Probably worth trying though?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2021 15:44 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/5 "2021-11-08T15:44:55Z")

</div>

Can't you just subtract 1 hour from the timestamp that you are generating in the function node?

---

<div class="post-metadata">

**Author:** ![dowermyr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dowermyr/32/31547_2.png) [@dowermyr](https://discourse.nodered.org/u/dowermyr)\
**Post date:** [8 November 2021 20:07 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/6 "2021-11-08T20:07:52Z")

</div>

I have a function node that calculates the lowess value and then i get a timestamp that look like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efada1a9d0357e1da033940c05f449a870509a80.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2021 21:09 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/7 "2021-11-08T21:09:25Z")

</div>

Is there a question there?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2021 21:45 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/8 "2021-11-08T21:45:27Z")

</div>

If you are asking how to subtract 1 hour from that, then in the function in the flow you posted where you have  
`new Date(msg.payload.totalMinimumStartsAt)`  
use  
`new Date(msg.payload.totalMinimumStartsAt).getTime() - 60 * 60 * 1000`  
That gives the timestamp in milliseconds, which I expect the node will be happy with. If not then add another `new Date()` round the whole thing, which will convert it back to a date.

---

<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:** [22 November 2021 21:45 UTC](https://discourse.nodered.org/t/cron-plus-1-hour/53381/9 "2021-11-22T21:45:44Z")

</div>

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