Urgent.News

650+ sources. One page. See who else covered it.

Editions

Tech

"Cron 'every 2 weeks' doesn't exist. Here's the expression that actually works."

You just Googled "cron every 2 weeks" because your clean-up job keeps running weekly, and the cron docs are silent on the whole idea. That's not your fault — the 5-field format has no concept of week parity. There's no */2w , no every-other . But there's a day-of-month trick that gives you a real biweekly cadence, and it's not what most people write. The trap most people fall into. Writing 0 0 *…

You have been searching for "cron every 2 weeks" because your maintenance job runs weekly, and the official documentation does not address this specific requirement. This is not your fault—the five-field format of cron does not account for week parity. There is no option to write */2w or every-other. However, there is a day-of-month workaround that provides a genuine biweekly cadence, and it is not what most people write.

The common mistake is to write 0 0 * * 1 (every Monday) and assume it means every other Monday. This does not work, as the expression fires every single Monday, every week, which is precisely what you were trying to avoid. The correct expression is: 0 0 1-7,15-21 * 1. Every 2 weeks on Monday at midnight. Monday occurs on day-of-month 1-7 in one week of the month and 15-21 in the next, so it runs exactly once per fortnight.

The same technique can be applied to other weekdays: 0 0 1-7,15-21 * 5 for every 2 weeks on Friday (payroll, reports), 0 9 8-14,22-28 * 3 for every 2 weeks on Wednesday at 9 AM, and 30 4 1-7,15-21 * 0 for every 2 weeks on Sunday at 4:30 AM. There are pitfalls to avoid, such as windows that end near day 28, as they disappear in months with fewer days.

It is preferable to use windows that never cross into the next month. If you want biweekly runs on a specific date like the 1st, this cannot be expressed within cron alone, as no day-of-month value represents every other month. A cleaner alternative would be to keep a weekly line (0 0 * * 1) as the trigger and use a small wrapper script to track a timestamp, skipping every other run.

This approach is simpler, more readable, and does not break in February. Application schedulers like APScheduler or croniter handle biweekly scheduling through simple calendar arithmetic without the need for day-of-month tricks. I've compiled a comprehensive reference of verified biweekly expressions, including this guide, at https://cron-generator-kappa.vercel.app/guides/cron-every-two-weeks.

Bookmark it to avoid reconstructing the windows from memory again. If your cron never seems to fire, the issue might be a timezone problem rather than the schedule itself. While cron's five fields cannot natively handle every 2 weeks, the day-of-month window is the workaround, and now you have the expressions to copy. What biweekly jobs do you run?

Every-other-Monday reports, or something else? I would be interested to hear what people are scheduling. The answers often reveal cleaner patterns than my day-of-month trick.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

PICK A PLATFORM, ANY PLATFORM...

// The Framework Shell Game // "Just pick one, they're all different!" // // 🥤 Angular? React in a trench coat. // 🥤 Vue? React with a fake mustache. // 🥤 Svelte? React playing dress-up.

  • Developers face multitude of web development platforms
  • Frameworks include React, Angular, Vue, Svelte, Solid, Qwik, Gatsby, Remix Run
  • Developers question true nature and motivations of frameworks

What Is DNS? A Simple Explanation for Beginners

Every time you type a website address into your browser, something happens behind the scenes that most people never think about.

  • DNS, or Domain Name System, acts as the internet's phonebook.
  • It translates user-friendly domain names into computer-readable IP addresses.
  • DNS streamlines web browsing by quickly resolving domain names to IP addresses.

More from Sunday 16 August →