Run a job every 2 hours
The cron expression for every 2 hours is 0 */2 * * *. The */2 step in the hour field fires at 00:00, 02:00, 04:00 and every even hour through 22:00, 12 times a day. Keep the 0 in the minute field: * */2 * * * runs every minute during those hours.
0*/2***Next 5 runs
Vercel always runs schedules in UTC, and GitHub Actions does unless you set a time zone. Crontab and Kubernetes use the server's time zone.
Field by field
0Minute- At minute 0
*/2Hour- Every 2nd hour: 0, 2, 4 … 22
*Day of month- Every day of the month
*Month- Every month
*Day of week- Every day of the week
By platform
Most schedulers take the same five fields. The wrapper, time zone and limits differ.
# m h dom mon dow command
0 */2 * * * /usr/local/bin/sync.sh >> /var/log/sync.log 2>&1Runs in the server's local time zone
on:
schedule:
- cron: "0 */2 * * *"Runs in UTC unless you set a time zone
timezone next to cron to use local time. Runs often start late when GitHub is busy, most of all at the start of an hour. In a public repository, GitHub turns the schedule off after 60 days without activity.spec:
schedule: "0 */2 * * *"
timeZone: "Etc/UTC"
concurrencyPolicy: ForbidWithout timeZone, the controller's zone applies
aws events put-rule \
--name sync-every-2-hours \
--schedule-expression "cron(0 0/2 * * ? *)"Six fields, and one day field must be ?
? in day-of-month or day-of-week. For a plain interval, rate(2 hours) is simpler, though its runs are timed from when you create the rule rather than by the clock.{
"crons": [
{ "path": "/api/sync", "schedule": "0 */2 * * *" }
]
}Needs a paid plan
Other 2-hour schedules
The step counts from midnight, not from when the job was installed. Start the range at 1 for odd hours, or change the minute to move runs off the hour.
| Expression | Runs |
|---|---|
0 0,2,4,6,8,10,12,14,16,18,20,22 * * * | Same as 0 */2 * * *, with the hours listed |
0 1-23/2 * * * | Every 2 hours on the odd hours, 01:00 through 23:00 |
30 */2 * * * | Every 2 hours at half past, 00:30 through 22:30 |
0 8-18/2 * * 1-5 | At 08:00, 10:00, 12:00, 14:00, 16:00 and 18:00, Monday through Friday |
Every 3, 4, 6, 8 or 12 hours
Change the step to change the interval. Each of these divides 24, so the runs stay evenly spaced across midnight. Keep a fixed minute (here 0) in the first field, as for every 2 hours.
| Interval | Expression | Runs | Starting later |
|---|---|---|---|
| Every 3 hours | 0 */3 * * * | 8 a day: 00:00, 03:00, 06:00 … 21:00 | 0 1-23/3 * * * |
| Every 4 hours | 0 */4 * * * | 6 a day: 00:00, 04:00, 08:00 … 20:00 | 0 2-23/4 * * * |
| Every 6 hours | 0 */6 * * * | 4 a day: 00:00, 06:00, 12:00, 18:00 | 0 3-23/6 * * * |
| Every 8 hours | 0 */8 * * * | 3 a day: 00:00, 08:00, 16:00 | 0 6-23/8 * * * |
| Every 12 hours | 0 */12 * * * | 2 a day: 00:00 and 12:00 | 0 6,18 * * * |
The last column shifts the same interval off midnight: 0 2-23/4 * * * runs at 02:00, 06:00, 10:00, 14:00, 18:00 and 22:00. Every 12 hours can also be written with the hours listed, as 0 0,12 * * *.
A step that doesn't divide 24 leaves a short gap at midnight, because the count starts again at 00:00 each day: 0 */5 * * * runs at 00:00, 05:00, 10:00, 15:00 and 20:00, then 4 hours later at midnight, and 0 */7 * * * runs at 00:00, 07:00, 14:00 and 21:00, then 3 hours later. For an exact interval like that, write one line per start time, as for every 90 minutes. On AWS EventBridge, rate(4 hours) counts from when the rule was created instead; the clock-aligned form is cron(0 0/4 * * ? *).
Every 2 hours in Jenkins, Quartz, Spring and systemd
Schedulers outside crontab write the same schedule differently: Jenkins picks the minute and hour offset for you, Quartz and Spring add a seconds field, and systemd uses calendar events.
| Scheduler | Every 2 hours | Notes |
|---|---|---|
| Jenkins | H H/2 * * * | Every 2 hours at a minute fixed per job, on the even or the odd hours depending on the job's name, so jobs don't all start at once. 0 */2 * * * also works |
| Quartz | 0 0 0/2 * * ? | Seconds come first, and one day field must be ?. 0 0 */2 * * * fails with “Support for specifying both a day-of-week AND a day-of-month parameter is not implemented”. 0 0 1/2 * * ? gives the odd hours |
| Spring @Scheduled | 0 0 */2 * * * | Six fields with seconds first; ? is optional. fixedRate = 2 with timeUnit = HOURS counts from startup instead of the clock |
| systemd timer | OnCalendar=0/2:00 | Normalizes to *-*-* 00/2:00:00, the even hours. Check it with systemd-analyze calendar '0/2:00' |
# /etc/systemd/system/job.timer (with a matching job.service)
[Timer]
OnCalendar=0/2:00
Persistent=true
[Install]
WantedBy=timers.targetPersistent=true runs a missed job once when the machine is back on, which cron never does. To run 2 hours after the last run started instead of on the clock, use a monotonic timer:
[Timer]
OnBootSec=10min
OnUnitActiveSec=2hOnBootSec starts the first run 10 minutes after boot, and OnUnitActiveSec=2h repeats it every 2 hours after that, so the times drift with boots rather than landing on even hours. The Quartz, Spring and systemd forms were checked with Quartz 2.5.1, Spring 6.2 and systemd-analyze.