# Date filter with if node and code node

**URL:** <https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569>\
**Category:** Questions\
**Tags:** if, code\
**Created:** [June 28, 2023, 8:42pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569 "2023-06-28T20:42:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Internalit\_Automatio](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/internalit_automatio/32/12481_2.png) [@Internalit\_Automatio](https://community.n8n.io/u/Internalit_Automatio)\
**Post date:** [June 28, 2023, 8:42pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/1 "2023-06-28T20:42:06Z")

</div>

hello community! How are you doing? me again! Sorry haha

I wanted to tell you that I am having a problem when filtering items, for example I have in the node “code” where I get the current date and in another node I have other dates, the problem is that when I place to filter the date with the code node, it is only comparing it with the first item that enters and not with the 730 that there are, now if I place the manual date in plain text, it compares it with all items, any idea what can be?

 ![Captura de Pantalla 2023-06-28 a la(s) 17.34.49](https://europe1.discourse-cdn.com/n8n/original/3X/8/a/8af4d79cedb4e73e7913af4751f0e5b695fa9804.png)

 ![Captura de Pantalla 2023-06-28 a la(s) 17.35.29](https://europe1.discourse-cdn.com/n8n/original/3X/2/d/2d32dcb5e06001ec46d6640d98ecd7836538c29b.png)

As always, thank you very much for your help!  
Regards,!

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 29, 2023, 8:23am UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/3 "2023-06-29T08:23:55Z")

</div>

Hi @Internalit_Automatio, based on your description I suspect your `dia_code` node returns only one item, could this be? If so, you would need to tell your If node to always read this first item, for example using an expression like this:

```auto
{{ $("dia_code").first().json.fecha }}

```

Without the .first() part (documented [here](https://docs.n8n.io/code-examples/methods-variables-reference/#output-of-other-nodes)), the If node would pull the first item of the dia\_code node for its own first item which works. Then for the second item it would try to pull the second item of the dia\_code node which fails, same for the third, fourth etc. item.

I hope this makes sense and helps! Let me know if that’s not it or if you have any further questions here 🙂

---

<div class="post-metadata">

**Author:** ![Internalit\_Automatio](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/internalit_automatio/32/12481_2.png) [@Internalit\_Automatio](https://community.n8n.io/u/Internalit_Automatio)\
**Post date:** [June 29, 2023, 2:10pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/4 "2023-06-29T14:10:44Z")

</div>

Hi @MutedJam  
First of all I would like to thank you for the help you have always given me! 💚

And here comes the question, I do not know if I understood correctly but I put: {{ $(“dia\_code”).all().json.fecha }} and I get an error, if I put last, first, it takes it well but of course, it does not compare it with all items, maybe something is wrong? My dia\_code node has this configuration:

 ![Captura de Pantalla 2023-06-29 a la(s) 11.08.31](https://europe1.discourse-cdn.com/n8n/original/3X/8/b/8b1749d16127527a8357fcec9be7289900c59bf4.png)

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 29, 2023, 2:25pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/5 "2023-06-29T14:25:32Z")

</div>

Oh, looks like your dia\_code node returns the current data but only applies it to the first item indicated by `items[0]`.

Is your goal simply to get today’s date? If so you could consider removing this Code node completely, and instead use an expression like `{{ $now.setZone("America/Buenos_Aires").toFormat("yyyy-MM-dd") }}` directly on the IF node:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/d/e/de302182ae53538663b16566975d0133ec40e2f3.png)

This way, you wouldn’t have to worry about other nodes at all and will compare today’s date for each incoming item 🙂

---

<div class="post-metadata">

**Author:** ![Internalit\_Automatio](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/internalit_automatio/32/12481_2.png) [@Internalit\_Automatio](https://community.n8n.io/u/Internalit_Automatio)\
**Post date:** [June 29, 2023, 2:32pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/6 "2023-06-29T14:32:49Z")

</div>

Oh my god you are amazing, always helping me and solving things!!! ❤ That worked for me! So you mean that if I want to get date, day, time “current” I can put directly in the IF and it compares everything, incredible!!! Thanks so much for the help and have a great week!!!

Regards!!

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 29, 2023, 2:33pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/7 "2023-06-29T14:33:43Z")

</div>

Thank you so much for your kind words, glad to hear this works for you 😊

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 6, 2023, 2:34pm UTC](https://community.n8n.io/t/date-filter-with-if-node-and-code-node/27569/8 "2023-07-06T14:34:01Z")

</div>

Closed on July 6, 2023, 2:34pm UTC

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