4

I am trying to create recurring job in hangfire that runs, once a month at the second Monday, something like this: 1. Monday, May 14, 2018 8:00 AM 2. Monday, June 11, 2018 8:0 AM 3. Monday, July 9, 2018 8:00 AM 4. Monday, August 13, 2018 8:00 AM 5. Monday, September 10, 2018 8:00 AM

I have found this answer in stackoverflow, but since this is not a standard cron for scheduling hangifre jobs I can not use it.

My question is can I make an expression like this using the format * * * * * (min hour day/month month day/week)

Ivan Ruski
  • 1,123
  • 1
  • 13
  • 19

4 Answers4

2

The following command seems to work for me.

0 8 ? * MON#2

Assuming that you want this job to execute at 8 AM the second Monday of each month, the # character allows you to specify the "nth" day of any given month. We use the ? character in the day/month row since we are fine with any numeric day as long as it is the second Monday.

Read more about special characters here: http://www.quartz-scheduler.org/documentation/quartz-2.2.2/tutorials/crontrigger.html#special-characters

LOLalert
  • 21
  • 2
0

Below are cron for three different time for every 2nd Monday, Look into the pattern and make change in time as per your need day

For each second Monday of the month at 00:00 hrs, try below: 0 0 0 ? 1/1 MON#2 *

For each second Monday of the month at 10:30 hrs, try below: 0 30 10 ? 1/1 MON#2 *

For each second Monday of the month at 13:30 hrs, try below: 0 30 13 ? 1/1 MON#2 *

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 08 '21 at 15:46
-1

Here you go.

0 0 12 ? 1/1 MON#2 *
-3
minute   hour   day   month   dayofweek   command   
0        0      8-14  *       2           /path/here

This will run a job every second tuesday of the month at midnight.

8-14 limits the occurance of tuesday to the second week in the month.

1-7 first week
8-14 second week
15-21 third week
22-28 forth week
29-31 fifth week
Bonsi
  • 48
  • 4
  • 5
    I don't think that this will work. In my opinion this expression is equal to `“At 00:00 every day from 8 through 14 and on Tuesday` – Ivan Ruski Apr 16 '18 at 07:12
  • Hmm.. that's odd, but yeah - it even says so in the English Wikipedia article to Cron - didn't know that this special rule even exists. – Bonsi Apr 17 '18 at 05:45