Search code examples
cronquartz-schedulerquartz

CronExpression every 2 days


I know this question was asked before. But the answers in those questions are not correct in my opinion.

I want to have a CronExpression for (Quartz) that schedules every 2 days. The CronExpression "should be" 0 0 0 1/2 * ? *.

BUT: Starting today (9th October 2017) CronMaker shows that this is not true. This expression basically means: schedule every 2 days starting on the first of each month. That means: starting on 9th October 2017 the next times are:

Wednesday, October 11, 2017 12:00 AM
Friday, October 13, 2017 12:00 AM
Sunday, October 15, 2017 12:00 AM
Tuesday, October 17, 2017 12:00 AM
Thursday, October 19, 2017 12:00 AM
Saturday, October 21, 2017 12:00 AM
Monday, October 23, 2017 12:00 AM
Wednesday, October 25, 2017 12:00 AM
Friday, October 27, 2017 12:00 AM
Sunday, October 29, 2017 12:00 AM
Tuesday, October 31, 2017 12:00 AM
Wednesday, November 1, 2017 12:00 AM

As you can see: There is only 1 day between the two last times.

So when I'm using freeformatter to describe the cronexpression it states:

At 00:00:00am, every 2 days starting on the 1st, every month

Well that is shown in the listed times above. But I need something that correctly fires every 2 days.

Tuesday, October 31, 2017 12:00 AM
Thursday, November 2, 2017 12:00 AM

and so on.

Apparently the simple trigger from quartz is not a real option for me!


Solution

  • It's becouse you misunderstood how cron expression works. For every month it will starts from first day of month. If it would work otherly, the next month wouldn't fit 1/2 part of expression.

    For more detailed explanation, look here:

    Quartz.net - Repeat on day n, of every m months?