Cron expression for daily at midnight

0 0 * * *

The job runs once a day at 00:00 in the scheduler's time zone. Many crons also accept @daily or @midnight for the same thing.

Runs when: minute 0; hour 0; every day of month; every month; any day of week.

Change it in the cron expression generator

How the five fields read

FieldValueReads as
Minute0at 0
Hour0at 0
Day of month*every value
Month*every value
Day of week*every value

The next five runs

What people use it for

Your midnight is not your user's midnight

The job fires at midnight where the scheduler runs, usually UTC, not where your customers are. For per-user daily work, run a job every 15 minutes and check each user's local time in code. Midnight is also the busiest mark on most servers, because backups, log rotation and reports all pick it, so consider 0 3 * * * or an odd minute such as 17 0 * * *.

Variations of daily at midnight

ExpressionWhat it does
0 3 * * *Daily at 03:00, a quieter slot than midnight.
17 0 * * *Daily at 00:17, off the crowded midnight mark.
0 0 * * 1-5Midnight on weekdays only.

The same schedule in four tools

Linux crontab

0 0 * * * /path/to/command

Add it with crontab -e. It runs in the machine's time zone.

Kubernetes CronJob

spec:
  schedule: "0 0 * * *"
  timeZone: "Etc/UTC"
  concurrencyPolicy: Forbid

timeZone is stable from Kubernetes 1.27. Without it, the controller's time zone applies. Forbid stops a new run starting while the last one is still going.

GitHub Actions

on:
  schedule:
    - cron: '0 0 * * *'

Schedules run in UTC from the default branch, and a run can start a few minutes late when GitHub is busy. Scheduled workflows in public repositories are disabled after 60 days without repository activity.

AWS EventBridge

cron(0 0 * * ? *)

EventBridge uses six fields, with a question mark in one of the two day fields, and rules run in UTC. Weekday numbers start at Sunday = 1, so names such as MON are safer than numbers.

Questions about daily at midnight

Is @midnight different from @daily?
No. In Vixie cron, @daily and @midnight both mean 0 0 * * *.
Does daylight saving affect a midnight job?
A few time zones change their clocks at midnight, so on those days local 00:00 can be skipped. Running the scheduler in UTC avoids it.

Nearby schedules

Scheduling jobs, pipelines and cloud infrastructure is part of my DevOps engineering work.