Bug in IF and SWITCH nodes - possibly when date/time functions are used

Describe the problem/error/question

I am trying to conditionally execute a branch based on the time of the day. The following is the logic used:

{{ ((d) => { const now = d.getTime(); const start = new Date(d); start.setHours(9,0,0,0); const end = new Date(d); end.setHours(21,0,0,0); return (now >= start.getTime() && now < end.getTime()) ? “call” : “do not call”; })(new Date($now)) }}

And the past execution clearly shows that this resolves to text “call”

However, the “do not call” branch is selected instead

What is the error message (if any)?

No error messages. n8n happily selects the wrong branch.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.107.0
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

is this what you are trying to do?

{{ $now.hour >= 9 && $now.hour <= 21 }}

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