Skip to main content

How to Run Cron Jobs Every 2 Weeks

Standard 5-field cron lacks native biweekly support. Learn the day-of-month window trick to run tasks every other week.

AI-written
Inewgen
16 Aug 2026Source: Dev.to2 min read (0 views)
Share
How to Run Cron Jobs Every 2 Weeks

Stock photo for illustration only, not from the actual event

Font size
  • The standard 5-field cron format does not support biweekly parity like */2w.
  • Using a standard weekly day expression runs the task every single week without fail.
  • Combining day-of-month ranges like 1-7 and 15-21 with a weekday solves this natively.

Many developers search for a clean way to run scheduled clean-up tasks every two weeks, only to find that official cron documentation remains silent on the topic. The core limitation stems from the 5-field format lacking any concept of week parity or dedicated alternating intervals.

A common mistake involves writing an expression such as 0 0 * * 1 while expecting it to mean every other Monday. In reality, that expression fires on every single Monday without exception, defeating the original automation goal entirely.

programming code computer screen dark mode

Stock photo for illustration only, not from the actual event

The reliable workaround relies on selecting day-of-month windows that occur during only one of the target weeks. By combining specific date ranges like 1-7 and 15-21 with a specific weekday, the task executes precisely once per fortnight across any month length.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

Understanding how cron intervals handle calendar mathematics prevents common scheduling bugs in production environments. While day-of-month tricks work well for simple cadence requirements, highly complex schedules benefit greatly from dedicated application schedulers or wrapper scripts that avoid calendar edge cases entirely.

Practical examples of verified expressions include:

  • 0 0 1-7,15-21 * 5 for biweekly Fridays used in payroll or routine reports.
  • 0 9 8-14,22-28 * 3 for biweekly Wednesdays scheduled precisely at 9:00 AM.
  • 30 4 1-7,15-21 * 0 for biweekly Sundays scheduled at 4:30 AM.

For scenarios requiring complex scheduling logic beyond basic intervals, fighting the native format is rarely optimal. Utilizing application schedulers like APScheduler or maintaining a simple wrapper script with timestamp tracking provides a robust, readable alternative that handles calendar anomalies smoothly.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article