Lorixen.
EN

Cron jobs skipped or run twice at daylight saving changes

Short answer: On the nights clocks change, cron jobs scheduled in the hour that's skipped or repeated can be skipped entirely or run twice, and which one happens depends on which cron program your server runs. Two widely used implementations document opposite behaviour. The simplest fix is to keep the server clock on UTC, or to schedule important jobs outside the change window, typically between 1 and 3 a.m. local time. Make jobs safe to run twice, and check after each change that they ran once.

The problem in plain terms

In much of the US, clocks jump forward one hour on a Sunday in spring and fall back one hour in the fall. Locally, that means:

  • Spring: a slice of local time, usually 2:00 to 2:59 a.m., never happens.
  • Fall: a slice of local time, usually 1:00 to 1:59 a.m., happens twice.

Night-time is exactly when businesses schedule things: nightly invoices, report emails, backups, data syncs, subscription renewals, cleanup jobs. A job at 2:30 a.m. might not run on the spring change. A job at 1:30 a.m. might run twice in the fall, sending duplicate emails or charging cards twice if the job isn't protected.

Two cron programs, two behaviours

"Cron" isn't one program. Linux distributions ship different implementations, and their manuals describe daylight saving time differently.

Debian's cron (also used by Ubuntu) has special handling. Its manual says that when the clock changes by less than three hours, as at the start and end of daylight saving time, jobs that would have run in skipped time are run soon after the change, and jobs that fall in repeated time aren't re-run. It adds that this applies only to jobs scheduled at a particular time; jobs with wildcards in the hour or minute fields, or @hourly, run based on the new time.

Cronie (common on Red Hat-family systems and others) documents the opposite in its crontab manual: non-existent times, such as the missing hour, never match, so jobs scheduled then don't run, and times that occur more than once cause matching jobs to run twice.

So the same crontab line can behave differently on two servers. If you've moved hosts or distributions, the behaviour may have changed without anyone noticing.

Option 1: run the server on UTC

UTC has no daylight saving changes. If the server's clock and cron run on UTC, every scheduled time happens exactly once, every day.

The trade-off is that jobs shift relative to local time twice a year: a job at 08:00 UTC runs an hour earlier or later on the local clock in summer than in winter. For backups and maintenance, that rarely matters. For customer-facing jobs, such as "send the daily summary at 7 a.m. local time", you may prefer to handle the local time zone in the job itself.

Option 2: use CRON_TZ deliberately

Cronie supports a CRON_TZ variable that sets a time zone for the jobs in a crontab, so you can keep the server on UTC but schedule specific jobs in local time. That brings back daylight saving behaviour for those jobs, so the next two options still apply. Debian's cron handles time zones differently; check your own manual before relying on this.

Option 3: avoid the change window

If jobs must run on local time, schedule them outside the hours that can be skipped or repeated. In the US that generally means avoiding roughly 1:00 to 3:00 a.m. local time. Midnight or 3:30 a.m. are common choices. Other countries change clocks at different times, so check the rules for each location you serve.

Option 4: make jobs safe to run twice, or late

Whatever you choose, design jobs so a duplicate or delayed run does no harm:

  • Record what's done. An invoice job should mark each invoice as sent, and skip anything already marked.
  • Use the date being processed, not "now". A daily report should process a specific day and refuse to process the same day twice.
  • Lock against overlap, so a second run waits or exits if the first is still going.
  • Catch up on missed days. If a run is skipped, the next run should notice and process the missing period.

Check after each change

Put the two change dates in your calendar and, the morning after, check:

  • Job logs show exactly one run for each scheduled job.
  • No duplicate emails, charges or exports went out.
  • Monitoring for "job didn't run" stayed quiet.

A simple heartbeat check, where each job pings a monitoring service when it finishes, catches skipped runs automatically.

Scheduling inside your app

If your app schedules jobs itself, through a framework scheduler or job queue, find out which time zone it uses and how it handles the change. Many app schedulers default to UTC; others follow the server or a configured zone. The same principles apply: prefer UTC for internal jobs, and handle local time explicitly where customers expect it.

A worked example

Take a hypothetical Kansas City dental practice software company whose nightly job emailed appointment reminders at 1:30 a.m. local time. After the fall change, some clinics' patients received two reminders. The server ran cronie, which runs jobs twice in a repeated hour. The team moved the server clock and crontab to UTC, scheduled the reminder job to match the clinics' preferred local time inside the job, and added a "reminder sent" flag per appointment so a second run would skip anything already sent. The next spring change passed with exactly one run.

FAQ

Does this affect hourly jobs?

Jobs with a wildcard hour usually run on the new time immediately, but behaviour varies. Check your implementation's manual.

Are cloud schedulers immune?

Many let you choose a time zone and document their own daylight saving handling. Read it before choosing local time.

Can I just avoid scheduling at 2 a.m.?

That helps for the US, but the repeated hour in the fall is usually 1 a.m. Avoid both, or use UTC.

What about servers in other countries?

Daylight saving rules differ by country and change occasionally. UTC avoids all of them.

If your scheduled jobs misbehave twice a year, tell us how they're scheduled and we'll help make them reliable.

Sources

WhatsAppBook a call