Issue
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:
- 2020/06/02 Tue 08:00:00
- 2020/07/07 Tue 08:00:00
- 2020/08/04 Tue 08:00:00
- 2020/09/01 Tue 08:00:00
- 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?
Solution
The first Monday of the month falls on one (and only one) of the dates from the first to the 7th inclusive. Then the cron expression will be easy to get it.
Suppose it should be 0 0 8 1-7 * Tue
and the below is my test, it shows the first five dates.
Answered By - George Chen Answer Checked By - Dawn Plyler (WPSolving Volunteer)