# Function Node: Time between 22:00 - 6:00

**URL:** <https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769>\
**Category:** General\
**Created:** [5 October 2020 13:25 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769 "2020-10-05T13:25:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![get-command](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/get-command/32/25038_2.png) [@get-command](https://discourse.nodered.org/u/get-command)\
**Post date:** [5 October 2020 13:25 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/1 "2020-10-05T13:25:44Z")

</div>

Hello forum,  
i would like to build a function node that only executes the next node under these conditions (Time between 22:00 - 6:00), otherwise just terminate it. Does anyone have an idea?

thank you in advance.

---

<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:** [5 October 2020 13:42 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/2 "2020-10-05T13:42:50Z")

</div>

I would probably use node-red-contrib-simple-gate to block the message, and control the gate by sending open/close messages from one of the scheduler nodes such as cron-plus or even from a couple of inject nodes set to fire at 22:00 and 06:00.

If you really want to do it in a function node as a learning exercise then start by looking at the javascript Date object.

---

<div class="post-metadata">

**Author:** ![get-command](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/get-command/32/25038_2.png) [@get-command](https://discourse.nodered.org/u/get-command)\
**Post date:** [5 October 2020 14:21 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/3 "2020-10-05T14:21:35Z")

</div>

> [@Colin](#):
>
> cron-plus

thank. in my case your idea doesn't work. I have a motion detector as a trigger. The cron plus node has no input.

---

<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:** [5 October 2020 14:29 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/4 "2020-10-05T14:29:49Z")

</div>

You misunderstand. Feed the motion detector into the gate node. When the gate is open it will pass any motion messages on, when the gate is closed it will block them. Also feed the cron-plus node into the gate and configure it to send the control messages that open and close the gate at the appropriate times.

---

<div class="post-metadata">

**Author:** ![get-command](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/get-command/32/25038_2.png) [@get-command](https://discourse.nodered.org/u/get-command)\
**Post date:** [5 October 2020 14:39 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/5 "2020-10-05T14:39:06Z")

</div>

Hi, sorry but i don't understand...

The Motion Detector Node has not input too

Here my flow:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/5552353b79e048bf343806020b0e641142df55e6.png)

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [5 October 2020 14:39 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/6 "2020-10-05T14:39:44Z")

</div>

Take a look : [https://flows.nodered.org/node/node-red-contrib-time-switch](https://flows.nodered.org/node/node-red-contrib-time-switch)

---

<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:** [5 October 2020 14:41 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/7 "2020-10-05T14:41:21Z")

</div>

Feed both the motion detector and the cron plus node into the gate.  
However the time switch node is a better way, I had forgotten about that one.

---

<div class="post-metadata">

**Author:** ![get-command](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/get-command/32/25038_2.png) [@get-command](https://discourse.nodered.org/u/get-command)\
**Post date:** [5 October 2020 15:14 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/8 "2020-10-05T15:14:17Z")

</div>

Super! that seems to be working. Thank you!

---

<div class="post-metadata">

**Author:** ![get-command](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/get-command/32/25038_2.png) [@get-command](https://discourse.nodered.org/u/get-command)\
**Post date:** [5 October 2020 15:14 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/9 "2020-10-05T15:14:58Z")

</div>

Thank you for Help.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [5 October 2020 16:23 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/10 "2020-10-05T16:23:43Z")

</div>

A few days ago I spotted this new node.

> [@\[ANNOUNCE\] node-red-contrib-chronos](https://discourse.nodered.org/t/announce-node-red-contrib-chronos/33350):
>
> Hi all, please be informed about my new node package called node-red-contrib-chronos. The package provides nodes to schedule, queue, route or filter messages based on fixed times or sun and moon position events. I hope you like it!

Might also be useful in that case.

---

<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:** [19 October 2020 16:23 UTC](https://discourse.nodered.org/t/function-node-time-between-22-00-6-00/33769/11 "2020-10-19T16:23:45Z")

</div>

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