Cron Quartz definitely not allowed to do this in a single statement. I get error message: "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."
How to execute cron quartz for the first Saturday and the first Sunday of each month
-
10-06-2023 - |
Question
I have tried with:
0 0 2 ? 1/1 SAT#1,SUN#1 *
but the result is wrong (only appears the sunday):
- Sunday, April 6, 2014 2:00 AM
- Sunday, May 4, 2014 2:00 AM
- Sunday, June 1, 2014 2:00 AM
- Sunday, July 6, 2014 2:00 AM
- Sunday, August 3, 2014 2:00 AM
also I have tried with:
0 0 2 1-7 * ? SAT,SUN
and a lot of variants but all of them are invalid syntax.
The correct output should be:
- Saturday, April 5, 2014 2:00 AM
- Sunday, April 6, 2014 2:00 AM
- Saturday, May 3, 2014 2:00 AM
- Sunday, May 4, 2014 2:00 AM
- Sunday, June 1, 2014 2:00 AM
- Saturday, June 7, 2014 2:00 AM . . . .
I've been doing all the tests since http://www.cronmaker.com/ (nice page!) unsuccessfully. Regards
La solution 4
Autres conseils
I've tried unsuccessfully too. In my opinion, Quartz Cron has some limitations.
By the way, can't you split your cron into two different schedules? For example:
0 0 2 ? 1/1 SAT#1 *
0 0 2 ? 1/1 SUN#1 *
0
and 7
stand for Sunday.
Hence, the numbers from 1
to 6
are fixed to Monday
, ..., Saturday
.
Graphically:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
0 0 1-7 * 0,6 * should work for you.
You have to split it to 2 cron expressions. From the documentation ( http://www.quartz-scheduler.org/api/2.2.0/org/quartz/CronExpression.html ) :
If the '#' character is used, there can only be one expression in the day-of-week field ("3#1,6#3" is not valid, since there are two expressions).