Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow use execution date: 'datetime' is undefined

Tags:

python

airflow

I want to use the execution time in Airflow and add one day to it:

'{{(execution_date + timedelta(days=1)).strftime("%Y-%m-%d")}}'

When I execute this I get

jinja2.exceptions.UndefinedError: 'timedelta' is undefined

How can I get the execution time plus one day?

like image 236
Juta Avatar asked Jul 16 '26 02:07

Juta


1 Answers

I found the answer here: https://diogoalexandrefranco.github.io/about-airflow-date-macros-ds-and-execution-date/

You can use:

'{{(execution_date + macros.timedelta(days=1)).strftime("%Y-%m-%d")}}'

The macros object exposes common python functions and libraries like macros.datetime and macros.timedelta

like image 106
Juta Avatar answered Jul 18 '26 15:07

Juta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!