- Home
- Tools
- Developer Tools
- Cron Expression Explainer
- Cron Expression for Every 2 Hours
Cron Expression for Every 2 Hours
0 */2 * * * runs a job every two hours, at 00:00, 02:00 and so on to 22:00. See the next runs, and how to move it to the odd hours.
At the start of every 2nd hour
| Field | Value | Matches |
|---|---|---|
| Minute | 0 | 0 |
| Hour | */2 | every 2nd hour from 0 to 22 |
| Day of month | * | every day of the month |
| Month | * | every month |
| Day of week | * | every day of the week |
Next 10 runs
Cron goes by the clock of the machine it runs on. These are the runs on a machine in your time zone.
On the even hours
0 */2 * * * runs at minute 0 of every second hour, counted from midnight: 00:00, 02:00, 04:00 and so on to 22:00. That is 12 runs a day. They are tied to the clock, not to the moment the crontab was saved.
| Expression | Runs |
|---|---|
| 0 */2 * * * | At the start of every 2nd hour |
| 0 1-23/2 * * * | At minute 0 of hours 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 and 23 |
| 30 */2 * * * | At minute 30 of every 2nd hour |
| 0 8-18/2 * * * | At 08:00, 10:00, 12:00, 14:00, 16:00 and 18:00 every day |
| * */2 * * * | Every minute during hours 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 and 22 |
| 0 */5 * * * | At 00:00, 05:00, 10:00, 15:00 and 20:00 every day |
Forgetting the zero
* */2 * * * is the classic slip. The hour field is right, but a star in the minute field means every minute, so the job runs 720 times a day: every minute of every even hour.
The odd hours
A step on a star always starts at 0. To run at 01:00, 03:00 and onwards, give the range yourself: 0 1-23/2 * * *.
Steps that don't fit the day
The count starts again at midnight. Two fits 24, so you never notice. Five doesn't: 0 */5 * * * runs at 00:00, 05:00, 10:00, 15:00 and 20:00, and the next run is four hours later, at midnight. Only 2, 3, 4, 6, 8 and 12 give an even rhythm in the hour field.
The cron expression explainer has the full syntax: the five fields, lists, ranges and steps, and how day of month and day of week work together.