Cron W (Nearest Weekday) Character
The W character, available in Quartz and Spring cron (not standard Linux cron), means 'the nearest weekday to this day of month'. It is used for things like 'run on the 15th, but if that falls on a weekend, use the closest Monday or Friday'.
How W works
15W in the day-of-month field means 'the weekday nearest the 15th'. If the 15th is a Saturday, it fires Friday the 14th; if Sunday, Monday the 16th. It never jumps across a month boundary.
Noon on the nearest weekday to the 15th: 0 0 12 15W * ? (Quartz, with ? in day-of-week).
LW — last weekday of the month
Combine with L: LW means the last weekday of the month. 0 0 12 LW * ? runs at noon on the final weekday — handy for month-end business jobs.
Not in Linux cron
Vixie/standard crontab does not support W. To approximate 'nearest weekday' on Linux, run on a range of days and add a date check in your script, or use a scheduler that supports Quartz syntax.
FAQ
What does 15W mean in cron?
The weekday nearest the 15th of the month. If the 15th is Saturday it runs Friday the 14th; if Sunday, Monday the 16th. It won't cross into another month.
What is LW in a cron expression?
The last weekday of the month. 0 0 12 LW * ? runs at noon on the final Mon-Fri day of the month.
Does Linux crontab support the W character?
No. W is a Quartz/Spring extension. On standard Linux cron, run on a day range and check the date in your script instead.