Cron expression for twice a day

0 8,20 * * *

The job runs at 08:00 and again at 20:00, every day. The comma is what makes it two separate runs.

Runs when: minute 0; hour at 8, 20; 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
Hour8,20at 8, 20
Day of month*every value
Month*every value
Day of week*every value

The next five runs

What people use it for

A dash is not a comma

0 8-20 * * * does not mean 08:00 and 20:00. A dash is a range, so that expression runs every hour from 08:00 through 20:00, thirteen times a day. A comma lists the exact values you want. If you want hours that are evenly spaced, 0 */12 * * * gives 00:00 and 12:00.

Variations of twice a day

ExpressionWhat it does
30 7,19 * * *Twice a day at 07:30 and 19:30.
0 9,17 * * 1-5Twice a day on weekdays, at 09:00 and 17:00.
0 */12 * * *Evenly spaced, at 00:00 and 12:00.

The same schedule in four tools

Linux crontab

0 8,20 * * * /path/to/command

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

Kubernetes CronJob

spec:
  schedule: "0 8,20 * * *"
  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 8,20 * * *'

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 8,20 * * ? *)

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 twice a day

How do I run three times a day?
List three hours: 0 8,13,18 * * * runs at 08:00, 13:00 and 18:00.
Can each run have a different minute?
Not in one line, because the minute field applies to every hour listed. Use two entries instead: 0 8 * * * and 30 20 * * *.

Nearby schedules

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