Comparing dates

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 :

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 :heart:

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

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

Not an exact answer to your question, but I'm using node-red-contrib-light-scheduler (node) - Node-RED for those needs.

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

const today = new Date().toLocaleDateString()
msg.payload = today

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.

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

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

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

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

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.

1 Like

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