Cron day of month and day of week: the "either" rule
This is the cron rule that surprises most people: two day fields do not combine with AND.
The rule
Cron has two fields that choose a day: the day of the month (field 3) and the day of the week (field 5). Minute, hour and month must all match. Then, for the two day fields, the manual says that if both fields are restricted, which means neither is a plain star, the command will be run when either field matches the current time. The cronie manual gives the example 30 4 1,15 * 5: it runs at 4:30 on the 1st and 15th of each month, plus every Friday.
The POSIX standard describes the same thing. If only the day-of-month is restricted, only it decides. If only the day-of-week is restricted, only it decides. If both are, a day that matches either one is chosen.
The tool shows it
Open the home page tool and type 30 4 1,15 * 5. The next runs are mixed: some on the 1st or 15th, some on Fridays. Now change the last field to a star: only the 1st and the 15th remain.
Examples that go wrong
| What you wanted | What you wrote | What actually runs |
|---|---|---|
| Friday the 13th | 0 9 13 * 5 | Every 13th and every Friday |
| First Monday of the month | 0 9 1-7 * 1 | Every day from the 1st to the 7th, and every Monday |
| Last Friday of the month | 0 9 25-31 * 5 | Every day from the 25th to the 31st, and every Friday |
What to do instead
Plain cron cannot AND the two fields. The accepted solution is to leave one of them as a star and add a test to the command line. For the first Monday of the month, run every Monday and let the shell test the date:
0 9 * * 1 [ "$(date +\%d)" -le 7 ] && /home/me/bin/job.sh
The percent sign has a backslash because cron would otherwise cut the line there. The test was tried for several dates in a shell: the first Mondays 2 November 2026, 7 December 2026 and 4 January 2027 passed, and 9 November was refused. For the last Friday, run every Friday and test that the date plus seven days falls in the next month.
Quartz does not have this problem, but it has a different rule: one of the two day fields must be a question mark ?, so there is no way to set both. They have special symbols instead: 6#1 is the first Friday, 2#1 the first Monday and 6L the last Friday (Quartz numbering, Sunday = 1).
A step in a day field
A star with a step, such as */2 in the day-of-month field, is a grey area. Cron programs differ in whether a leading star with a step counts as restricted or not. The tool above warns you when you combine a */n day field with a value in the other day field. The simplest advice: never combine them.
Does the rule apply in GitHub Actions and Kubernetes?
Both document POSIX-style cron, so the same rule is expected. The documents we read do not repeat it, so test your own schedule before you rely on it.
Is there a way to run only when BOTH match?
Not in the fields. Set one field to a star and test the other in the command, as above.
This is an independent guide and tool. It is not connected with crontab.guru, Quartz, GitHub, Kubernetes, Spring or the Linux projects named here. Product names belong to their owners.