Lee Learns

Templating and data intervals

What problem(s) it solves

Templating can be used in a lot of ways, but it tends to be super helpful for time-related string manipulation.

Without templating, you might have an ETL workflow that has executes a SQL query with a DATE. That query might be hard-coded into the "extract" task.

**In Airflow, a DagRun object has a data_interval_start and data_interval_end:

Screenshot 2025-08-07 at 3

Simply put, a data interval represents the specific time range that a DAG run is responsible for processing. (source)

A problem arises when you have dates hard-coded in the tasks (10:00, for example) -- you'd run the same sql query for every dag run.

Screenshot 2025-08-07 at 3

Instead, you want to run the query for the correct data interval: 10:00, 10:10, 10:20, ...

With templating you can do things like inject the date at runtime. It makes tasks idempotent.

Implementation

Simple example:

BashOperator(task_id="print_day_of_the_week", bash_command="echo Today is {{ data_interval_start.format('dddd') }}"

Here are special variables and functions you can use are referenced in the Templates reference. It uses Jinja, so you can do extra Jinja stuff, too.

#airflow