# Use today as filter

**URL:** <https://discourse.nodered.org/t/use-today-as-filter/76841>\
**Category:** General\
**Created:** [22 March 2023 21:24 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841 "2023-03-22T21:24:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [22 March 2023 21:24 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/1 "2023-03-22T21:24:36Z")

</div>

Hi.

I got several payloads that looks like attached picture with different start dates. Can I somehow just let the messengers pass with todays start date? My idea for now is to start with adjust the format on the date and maybe use a swith node with property payload.start\_date and an expression to filter out today.

I am stuck and tried google a lot to solve this without success 🙂

 ![Skärmavbild 2023-03-22 kl. 22.15.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8ab8518c8c182d4d18d53a32b3b1ebb1ee19a526.png)

```auto
[{"id":"bacc35bea7d25bee","type":"inject","z":"efbc49d0a7529b05","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":100,"wires":[["4bc1d3788c2f0e97"]]},{"id":"a0b3732a8e570fe9","type":"debug","z":"efbc49d0a7529b05","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":100,"wires":[]},{"id":"4bc1d3788c2f0e97","type":"template","z":"efbc49d0a7529b05","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"id\":[\"ID:397_207781203_14756\"],\"name\":[\"test\"],\"start_date\":[\"2023-03-24 19:00:00\"],\"end_date\":[\"2023-03-24 22:30:00\"]}","output":"json","x":540,"y":100,"wires":[["a0b3732a8e570fe9"]]}]

```

---

<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:** [22 March 2023 21:47 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/2 "2023-03-22T21:47:33Z")

</div>

For sure you can do this with some jsonata $moment expression in Switch node ..  
i took the javascript road if you are interested here is an example flow

```auto
[{"id":"bacc35bea7d25bee","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":2040,"wires":[["4bc1d3788c2f0e97"]]},{"id":"a0b3732a8e570fe9","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":2080,"wires":[]},{"id":"4bc1d3788c2f0e97","type":"template","z":"54efb553244c241f","name":"2023-03-24 19:00:00","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"id\": [\n \"ID:397_207781203_14756\"\n],\n \"name\": [\n \"test\"\n],\n \"start_date\": [\n \"2023-03-24 19:00:00\"\n],\n \"end_date\": [\n \"2023-03-24 22:30:00\"\n]\n}","output":"json","x":420,"y":2040,"wires":[["49d6dd8b4b7c3cd0"]]},{"id":"49d6dd8b4b7c3cd0","type":"function","z":"54efb553244c241f","name":"filter today","func":"let startdate = msg.payload.start_date[0].split(\" \")[0]\n// node.warn(startdate);\nlet today = new Date().toISOString().split(\"T\")[0]\n// node.warn(today);\n\nif (startdate === today) {\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":2080,"wires":[["a0b3732a8e570fe9"]]},{"id":"1d47e11a1a9696ba","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":2120,"wires":[["76df50776619040b"]]},{"id":"76df50776619040b","type":"template","z":"54efb553244c241f","name":"2023-03-22 11:00:00","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n \"id\": [\n \"ID:397_207781203_14756\"\n],\n \"name\": [\n \"test\"\n],\n \"start_date\": [\n \"2023-03-22 11:00:00\"\n],\n \"end_date\": [\n \"2023-03-24 22:30:00\"\n]\n}","output":"json","x":420,"y":2120,"wires":[["49d6dd8b4b7c3cd0"]]}]

```

---

<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:** [22 March 2023 22:09 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/3 "2023-03-22T22:09:00Z")

</div>

Using a switch node and JSONata expressions

```auto
[{"id":"bacc35bea7d25bee","type":"inject","z":"8be23377afc3327e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":[\"ID:397_207781203_14756\"],\"name\":[\"test\"],\"start_date\":[\"2023-03-24 19:00:00\"],\"end_date\":[\"2023-03-24 22:30:00\"]}","payloadType":"json","x":390,"y":320,"wires":[["c61d25aedb3fac25"]]},{"id":"c61d25aedb3fac25","type":"switch","z":"8be23377afc3327e","name":"","property":"$split($$.payload.start_date[0], \" \")[0]","propertyType":"jsonata","rules":[{"t":"eq","v":"$moment().format(\"YYYY-MM-DD\")","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":570,"y":320,"wires":[["a0b3732a8e570fe9"]]},{"id":"d2e9e594e61d83f9","type":"inject","z":"8be23377afc3327e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":[\"ID:397_207781203_14756\"],\"name\":[\"test\"],\"start_date\":[\"2023-03-22 19:00:00\"],\"end_date\":[\"2023-03-22 22:30:00\"]}","payloadType":"json","x":390,"y":360,"wires":[["c61d25aedb3fac25"]]},{"id":"a0b3732a8e570fe9","type":"debug","z":"8be23377afc3327e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":320,"wires":[]}]

```

 ![chrome_screenshot_1679522991679](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c78f88441f1a28a5fa5c92d019d6ebce8490f3d.png)

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [23 March 2023 19:40 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/4 "2023-03-23T19:40:57Z")

</div>

Thank you! You guys are really awsome 👍🏻  
Exactly what i was looking for.

But i can’t get this to work. Got nothing in debug when importing your examples. Am i running a to old version of node red. V2.2

Best regards

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [23 March 2023 20:11 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/5 "2023-03-23T20:11:16Z")

</div>

Not wery good in JSONata expressions. But after the split function it is missplaced in the array so it cant´t find the payload in payload.start\_date anymore. Can this be the problem?

![clip](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38932a0dc0c1326295d5243667cc3c69af0dff3a.jpeg)

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [23 March 2023 20:24 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/6 "2023-03-23T20:24:57Z")

</div>

Thanks again!! Got it to work 😀

---

<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:** [6 April 2023 20:25 UTC](https://discourse.nodered.org/t/use-today-as-filter/76841/7 "2023-04-06T20:25:35Z")

</div>

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