Tips for Working with Dates in Rules

Hey everyone! I wanted to share a quick tip that might help those of you working with dates in your rules. I recently stumbled upon a question where someone wanted to exclude a specific date from their automation. It got me thinking about how we can handle dates more effectively in our rules.

So, the challenge was to prevent an automation from running on October 31st every year. The user tried something like if (date != October 31) { ... }, but it didn’t work as expected. After digging around, I found that using DateTime functions can be a great way to handle this.

Here’s a simple example of how you can exclude a specific date:

rule “Exclude October 31”
when
Item MyCalendar changed
then
if (DateTime.now().dayOfMonth != 31 || DateTime.now().month != 10) {
// Your automation logic here
}
end

This rule checks both the day and the month to ensure it doesn’t run on October 31st. It’s a neat way to handle date-specific exclusions without getting too complicated.

If you have other date-related challenges or tips, I’d love to hear about them! Let’s keep sharing and learning together. :rocket: