atifaziz / NCrontab

Crontab for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crontab expression for every first tuesday of every month

HeinPauwelyn opened this issue · comments

How could I create an timer trigger with Azure Functions (version 3 and .NET Core) that must be executed every first Tuesday from every month at 8 AM. Starting from now (05/08/2020) this must be the next five occurrences:

  1. 2020/06/02 Tue 08:00:00
  2. 2020/07/07 Tue 08:00:00
  3. 2020/08/04 Tue 08:00:00
  4. 2020/09/01 Tue 08:00:00
  5. 2020/10/06 Tue 08:00:00

By using www.cronmaker.com, I've next NCRONTAB:

0 0 8 ? 1/1 TUE#1 *

But then I've next exception:

The schedule expression 0 0 8 ? 1/1 Tue#1 * was not recognized as a valid CRON expression or TimeSpan string.

Then I've start changing the CRON expression to next varations:

CORN Result
0 0 8 ? 1/1 Tue#1 Error from above
0 0 8 * 1/1 Tue#1 Error from above
0 0 8 1/1 Tue#1 * Error from above
0 0 8 * 1/1 Tue 1 Error from above
0 0 8 ? 1/1 Tue 1 Error from above
0 0 8 * 1/1 Tue/1 2020/05/29 08:00:00 - 2020/05/30 08:00:00
0 0 8 * * Tue/2 2020/05/30 08:00:00 - 2020/06/02 08:00:00
0 0 8 * 1/1 Tue/2 2020/05/30 08:00:00 - 2020/06/02 08:00:00
0 0 8 ? 1/1 Tue/2 Error from above

So every expression I've made, would not work as expected. My question is now: What's the correct expression?

This library only supports the original contrab expression. The #1 modifier is an extension, which is why you get an error. CronMaker specifically states that “Generated expressions are based on Quartz cron format.”

A first Tueday of a month can only occur on days 1-7, so you could use the 0 8 1-7 * Tue expression to effectively get 8 AM on first seven days of any month that's a Tuesday.

@HeinPauwelyn Consider closing this issue if the question's been answered.