Using Switch with Date/Time

I am trying to achieve the following (I am totally new to n8n):

  • Create a workflow that sends two slack messages first one at 8am, second one at 11am.

Approach:
1- Using Cron every hour.
2- Using a switch that calculate {{new Date().getHours()}}
3- if the value equals 8 flow will go to switch#0
4- if the value equals 11 flow will go to switch#1

Problem:

The expression doesn’t seem to work as I am not seeing any of the conditions are met, in the attached screenshot I did a test with 0, is this an expected behaviour? any workarounds?

Hi @Atheer_Al_Attar :wave: Welcome to the community :tada:

If you want to do this in one workflow instead of having two workflows (one for the first message and one for the second on separate cron schedules), you can do something like this:

In short, it looks like you were pretty close :slight_smile: This was me testing, with a message at 50 past and 52 past the hour. In your case, you’d need to switch the expression over to {{ DateTime.now().hour }} :slight_smile:

1 Like

Thanks @EmeraldHerald your workflow solved it!

I also figured out that my local time zone is different from what set on n8n, not sure if that contributed to the issue.

1 Like

Hi @Atheer_Al_Attar - glad to hear it helped!

That also can cause issues, it’s best to keep n8n and your computer synced :smiley:

1 Like

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