# Comparing dates

**URL:** <https://discourse.nodered.org/t/comparing-dates/80735>\
**Category:** General\
**Created:** [23 August 2023 08:00 UTC](https://discourse.nodered.org/t/comparing-dates/80735 "2023-08-23T08:00:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mugur09](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mugur09/32/78209_2.png) [@mugur09](https://discourse.nodered.org/u/mugur09)\
**Post date:** [23 August 2023 08:00 UTC](https://discourse.nodered.org/t/comparing-dates/80735/1 "2023-08-23T08:00:31Z")

</div>

Hello!  
I'm struggling with comparing dates.  
I would like a function or a node that checks today's date and compares it with a list of dates that i provide. If it matches, an output should go true.

This is my pattern :

 ![IMG_20230824_073609](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/0193f73567788ac60ec983abf72543334653f927.jpeg)

I'm trying to setup my heating system so that it will turn on for 15min before I wake up only on my morning shifts.  
Thanks! Amazing community! I love node red ❤

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 August 2023 08:10 UTC](https://discourse.nodered.org/t/comparing-dates/80735/2 "2023-08-23T08:10:13Z")

</div>

An alternative is to make it event based.

Using cron-plus you can "add" schedules that will trigger exactly when you say so.

example: [Dynamic cron schedules / timers via dashboard control (flow) - Node-RED](https://flows.nodered.org/flow/79a66966a6cc655a827872a4af794b94)

* * *

You can also feed the cron-plus exact dates and times (it doesnt have to be a crontab schedule).

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [23 August 2023 19:13 UTC](https://discourse.nodered.org/t/comparing-dates/80735/3 "2023-08-23T19:13:27Z")

</div>

Not an exact answer to your question, but I'm using [node-red-contrib-light-scheduler (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-light-scheduler) for those needs.

---

<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:** [23 August 2023 20:35 UTC](https://discourse.nodered.org/t/comparing-dates/80735/4 "2023-08-23T20:35:09Z")

</div>

If you do want to do it by comparing today's date with a list then the first problem is getting today's date allowing for your local timezone. You should be able to do that in a function node using  
`const today = new Date().toLocaleDateString()`  
To check that out try a function node containing just

```auto
const today = new Date().toLocaleDateString()
msg.payload = today
return

```

Trigger that with an Inject node and feed it into a debug node to see what you get. You should get a string containing today's date, using your locale's date format, which you can then compare with your list of dates.

---

<div class="post-metadata">

**Author:** ![mugur09](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mugur09/32/78209_2.png) [@mugur09](https://discourse.nodered.org/u/mugur09)\
**Post date:** [24 August 2023 05:53 UTC](https://discourse.nodered.org/t/comparing-dates/80735/5 "2023-08-24T05:53:54Z")

</div>

Thanks!  
I'll give it a try and I'll let you all know!

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [24 August 2023 18:03 UTC](https://discourse.nodered.org/t/comparing-dates/80735/6 "2023-08-24T18:03:35Z")

</div>

And what about a node, which reads your shifts directly from a calendar?

---

<div class="post-metadata">

**Author:** ![mugur09](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mugur09/32/78209_2.png) [@mugur09](https://discourse.nodered.org/u/mugur09)\
**Post date:** [24 August 2023 21:18 UTC](https://discourse.nodered.org/t/comparing-dates/80735/7 "2023-08-24T21:18:15Z")

</div>

Now that would be great! I tried google nodes but i got tangled in setup

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [25 August 2023 08:23 UTC](https://discourse.nodered.org/t/comparing-dates/80735/8 "2023-08-25T08:23:37Z")

</div>

I use `node-red-contrib-ical-events` version 2.2.2, installed via palette.

The node "Trigger" will check for new events.  
You need a iCal / ics / caldav URL or a filepath to ics.

See the docs at

> **[trigger | kalender-events](https://naimo84.github.io/kalender-events/guide/trigger.html)**
>
> This Node module gets the events from an ical-URL, a caldav-server or from iCloud.

Personally I use a CalDav server, check every 10 minutes for events with an offset of -6 hours.  
AFAIR the biggest problem was to get the right name for the calendar in the calendar field.  
I use Trigger "Match" for location (Filter property) and then the desired location.

BTW: I use it to get the date for the next garbage collection and then send a Telegram to the family chat.

---

<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:** [8 September 2023 08:24 UTC](https://discourse.nodered.org/t/comparing-dates/80735/9 "2023-09-08T08:24:37Z")

</div>

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