DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

Cron Expressions in Airflow: Understanding `00 3 * * 1-7`

If you are working with Apache Airflow, Linux, automation, or data pipelines, you will eventually encounter cron expressions.

At first, something like this can look confusing:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode

But once you understand what each part represents, cron schedules become very easy to read and create.

In this article, we will break down the cron expression 00 3 * * 1-7, explain each component, and show how it is used in Airflow.

What Is a Cron Expression?

A cron expression is a format used to define when a scheduled task should run.

Cron is commonly used in:

  • Linux and Unix systems
  • Apache Airflow
  • Data engineering pipelines
  • Database jobs
  • ETL and ELT processes
  • Backup automation
  • Application maintenance
  • Server monitoring

A traditional cron expression contains five fields:

┌───── Minute
│ ┌─── Hour
│ │ ┌─ Day of month
│ │ │ ┌─ Month
│ │ │ │ ┌─ Day of week
│ │ │ │ │
00  3  *  *  1-7
Enter fullscreen mode Exit fullscreen mode

Each field tells the scheduler a different part of the schedule.


Understanding 00 3 * * 1-7

Let's break it down:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode
Field Value Meaning
Minute 00 At minute 0
Hour 3 At 3 AM
Day of month * Every day
Month * Every month
Day of week 1-7 Monday through Sunday

Therefore:

00 3 * * 1-7 means run the task every day at 3:00 AM.


1. The Minute Field - 00

The first field represents the minute.

00
Enter fullscreen mode Exit fullscreen mode

This means the task runs at minute zero.

For example:

3:00 AM
4:00 AM
5:00 AM
Enter fullscreen mode Exit fullscreen mode

If you used:

30
Enter fullscreen mode Exit fullscreen mode

instead, the task would run at:

3:30 AM
Enter fullscreen mode Exit fullscreen mode

So:

00 3
Enter fullscreen mode Exit fullscreen mode

means:

At exactly 3:00.


2. The Hour Field - 3

The second field represents the hour.

3
Enter fullscreen mode Exit fullscreen mode

This means 3 AM.

Combined with the first field:

00 3
Enter fullscreen mode Exit fullscreen mode

we get:

3:00 AM.

For example:

00 1
Enter fullscreen mode Exit fullscreen mode

means 1:00 AM.

00 6
Enter fullscreen mode Exit fullscreen mode

means 6:00 AM.

30 18
Enter fullscreen mode Exit fullscreen mode

means 6:30 PM.

Cron generally uses the 24-hour clock, so:

3  = 3 AM
12 = 12 PM
15 = 3 PM
18 = 6 PM
23 = 11 PM
Enter fullscreen mode Exit fullscreen mode

3. Day of Month - *

The third field represents the day of the month.

*
Enter fullscreen mode Exit fullscreen mode

The asterisk means:

Every possible value.

Therefore:

*
Enter fullscreen mode Exit fullscreen mode

in this position means every day of the month:

1
2
3
4
...
31
Enter fullscreen mode Exit fullscreen mode

This means there is no restriction based on the date.


4. Month - *

The fourth field represents the month.

Again, we have:

*
Enter fullscreen mode Exit fullscreen mode

This means:

Every month.

Therefore, the schedule applies to:

January
February
March
April
...
December
Enter fullscreen mode Exit fullscreen mode

There is no restriction on the month.


5. Day of Week - 1-7

The final field represents the day of the week.

1-7
Enter fullscreen mode Exit fullscreen mode

The range means Monday through Sunday.

Typically:

1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
7 = Sunday
Enter fullscreen mode Exit fullscreen mode

Therefore:

1-7
Enter fullscreen mode Exit fullscreen mode

means:

Every day of the week.

So the entire expression:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode

means:

Run every day at 3:00 AM.


Cron Schedule Examples

Understanding a few examples makes cron much easier.

Every day at 3:00 AM

00 3 * * *
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run every day at 3:00 AM.

You could also write:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode

Both express a daily schedule.

Every day at 6:30 AM

30 6 * * *
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run every day at 6:30 AM.

Every Monday at 3:00 AM

00 3 * * 1
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run every Monday at 3:00 AM.

Every Friday at 5:00 PM

00 17 * * 5
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run every Friday at 5:00 PM.

Every hour

00 * * * *
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run at minute 0 of every hour.

For example:

1:00
2:00
3:00
4:00
...
Enter fullscreen mode Exit fullscreen mode

Every 15 minutes

*/15 * * * *
Enter fullscreen mode Exit fullscreen mode

Meaning:

Run every 15 minutes.

For example:

12:00
12:15
12:30
12:45
1:00
Enter fullscreen mode Exit fullscreen mode

Using Cron Expressions in Apache Airflow

Cron expressions are particularly useful in Apache Airflow because they allow you to control when DAGs should run.

For example:

from airflow import DAG

dag = DAG(
    dag_id="daily_pipeline",
    schedule="00 3 * * *",
)
Enter fullscreen mode Exit fullscreen mode

This tells Airflow to schedule the DAG:

Every day at 3:00 AM.

You may also encounter:

schedule="00 3 * * 1-7"
Enter fullscreen mode Exit fullscreen mode

This explicitly specifies Monday through Sunday.

In this particular case, however, the simpler:

schedule="00 3 * * *"
Enter fullscreen mode Exit fullscreen mode

is easier to read because the * already means every day of the week.


Be Careful With Timezones in Airflow

One of the most important things to understand when working with Airflow schedules is the timezone.

Suppose your Airflow environment uses UTC.

If your DAG is scheduled for:

03:00 UTC
Enter fullscreen mode Exit fullscreen mode

and you are working in Kenya, which uses East Africa Time (EAT), that corresponds to:

06:00 AM EAT
Enter fullscreen mode Exit fullscreen mode

So if your intention is:

Run the pipeline at 3:00 AM Kenya time

you need to make sure your Airflow DAG and environment are configured with the appropriate timezone.

This is especially important for data engineering teams working across countries and regions.


Why Cron Expressions Matter in Data Engineering

Cron schedules are commonly used to control the execution of data pipelines.

For example, imagine you have a pipeline that:

  1. Extracts data from a source database
  2. Loads the data into a data lake
  3. Transforms the data using dbt
  4. Updates a data warehouse
  5. Makes the data available for reporting

You might schedule the pipeline to run every morning:

00 3 * * *
Enter fullscreen mode Exit fullscreen mode

The pipeline would then be triggered every day at 3:00 AM.

This is particularly useful when data needs to be processed before business users start working in the morning.


A Simple Way to Read Cron

Whenever you see a cron expression, read it from left to right:

MINUTE
HOUR
DAY OF MONTH
MONTH
DAY OF WEEK
Enter fullscreen mode Exit fullscreen mode

For:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode

you can translate it mentally as:

00    -> minute 0
3     -> hour 3
*     -> every day
*     -> every month
1-7   -> Monday to Sunday
Enter fullscreen mode Exit fullscreen mode

Then combine everything:

Every day at 3:00 AM.


Quick Cron Cheat Sheet

Cron Meaning
00 3 * * * Every day at 3:00 AM
00 3 * * 1 Every Monday at 3:00 AM
00 3 * * 1-5 Monday to Friday at 3:00 AM
00 3 * * 1-7 Every day at 3:00 AM
30 6 * * * Every day at 6:30 AM
00 12 * * * Every day at noon
00 18 * * 5 Every Friday at 6:00 PM
*/15 * * * * Every 15 minutes
00 * * * * Every hour
00 0 1 * * First day of every month at midnight

Final Takeaway

The cron expression:

00 3 * * 1-7
Enter fullscreen mode Exit fullscreen mode

means:

Run every day of the week at exactly 3:00 AM.

The five cron fields are:

00    3    *    *    1-7
│     │    │    │      │
│     │    │    │      └── Day of week
│     │    │    └───────── Month
│     │    └────────────── Day of month
│     └─────────────────── Hour
└───────────────────────── Minute
Enter fullscreen mode Exit fullscreen mode

Once you understand these five fields, you can read most basic Linux cron and Apache Airflow schedules without having to memorize them.

Top comments (0)