Run a cron job daily at midnight: 0 0 * * * explained

0 0 * * * runs a job at exactly midnight (00:00) every day. The first zero fixes the minute to :00, the second zero fixes the hour to 0 (midnight in 24-hour time). This is the standard pattern for daily database backups, report generation, and log summarization.

Schedule pattern
Daily at midnight
daily-midnight
Category
Common Patterns
Standard cron expression patterns

How this is calculated

Midnight cron jobs run in the server's local timezone, which is typically UTC on cloud VMs and containerized environments. A 0 0 * * * job on a UTC server runs at 00:00 UTC, which might be 5 PM or 8 PM in your local time depending on your timezone. If you need the job to run at local midnight, either set the server's timezone or adjust the hour field: for EST (UTC-5), use 0 5 * * *. The @daily and @midnight shortcuts are equivalent to 0 0 * * *.

Verdict

0 0 * * * is correct for daily midnight execution, but always confirm the server timezone first. A job you think runs at midnight local time might actually be firing in the middle of the afternoon. Document the intended timezone next to the cron expression in your crontab.

More Cron scenarios

Frequently asked questions

What is a Cron Job?
A cron job is a scheduled task that runs automatically on a Unix-like operating system (like Linux or macOS) at specific intervals. It is heavily used by developers to run background tasks like database backups, cache clearing, or sending nightly emails.
What do the 5 parts of a cron expression mean?
From left to right, the 5 fields are: Minute (0-59), Hour (0-23), Day of the Month (1-31), Month (1-12), and Day of the Week (0-6, where 0 and 7 are Sunday).
What does the asterisk (*) mean in Cron?
The asterisk acts as a wildcard, meaning 'every'. For example, if the minute field is an asterisk, the task runs every single minute. If the month field is an asterisk, the task runs every single month.
How do I run a task every 5 minutes?
To run a task every 5 minutes, use the slash operator in the minute field like this: */5 * * * *. The */5 means 'every 5th minute'.