Cron daily at midnight (0 0 * * *): @daily, time zones and a better hour

Open this example in the tool

Try it in the tool

Cron Expression Parser

Read cron schedules in plain English and see when they run next.

Cron Expression Generator

Pick a schedule, get the cron expression and its next run times.

0 0 * * * runs once a day, at minute 0 of hour 0: midnight. The cron parser describes it as “At 00:00” and lists a run per day. The shortcuts @daily and @midnight mean the same on Vixie-style cron.

0 0 * * * /usr/local/bin/rotate-reports.sh >> /var/log/reports.log 2>&1

Whose midnight?

Cron uses the time zone of the system it runs on, and cloud servers are usually set to UTC. A team in Ho Chi Minh City (UTC+7) that writes 0 0 * * * on such a server gets its job at 07:00 local time. To run at local midnight on a UTC server, schedule 17:00 UTC:

0 17 * * *     # 00:00 in UTC+7 (Vietnam has no daylight saving)

Some cron versions accept CRON_TZ=Asia/Ho_Chi_Minh before the line, but it is not universal. Make the zone explicit in a comment next to the line so that the next person does not have to guess.

Why midnight is a poor choice

  1. Everyone picks it. Backups, log rotation, billing jobs and statistics all start at 00:00, so the machine and any shared service are busiest at that instant.
  2. The date changes during the run. A job that starts at 23:59:50 on one day and reads “today” at 00:00:05 sees two different days. Jobs that start exactly at midnight avoid this, but anything that runs a few minutes long can still cross over.
  3. Daylight saving. In zones that change the clock at midnight or in the small hours (some countries did, or still do), local midnight may happen twice or not at all, so a job tied to it runs twice or never. A UTC server avoids the problem, and the arithmetic in cron and time zones explains the rest.

A quiet moment with an uneven minute is better: 17 2 * * * runs at 02:17.

Daily variants

Goal Expression
Every day at 02:17 17 2 * * *
Every day at 06:00 and 18:00 0 6,18 * * *
Weekdays at midnight 0 0 * * 1-5
Once a week, on Sunday at midnight 0 0 * * 0
First day of each month 0 0 1 * * — see first day of the month

Make a daily job safe to run

  • Idempotent. A job that runs twice, or is run by hand again, must not duplicate its results.
  • Not dependent on “yesterday” computed from now. Pass the date to process as a parameter, so that a delayed or repeated run still handles the right day.
  • Logged and monitored. Cron does not tell you that nothing happened. Use a dead-man’s switch service that alerts you when the heartbeat stops, or at least check the log.

For a more frequent job, see every hour and every 6 hours. Check an expression and the next run times with the cron builder.

Frequently asked questions

What is the cron expression for once a day at midnight?

0 0 * * *: minute 0, hour 0, every day. @daily and @midnight are shortcuts for the same schedule on most systems.

Whose midnight is it?

The time zone of the cron daemon, which on most servers is UTC. For a business in Vietnam (UTC+7), 0 0 * * * on a UTC server runs at 07:00 local time. Convert the hour, or set CRON_TZ where your cron supports it.

Why avoid midnight for jobs?

Midnight is when many other things start: log rotation, backups, reports, cron jobs of other teams. It is also the busiest moment for date-based logic, because the date changes in the middle of a run. A time such as 02:17 is calmer.

What if the server is off at midnight?

The run is lost. Plain cron does not catch up. Use anacron or a systemd timer with Persistent=true, which run the job once the machine is back.

More in this reference