Airflow has no influence on the date.today()
function.
In fact, if you use this approach you remove one of Airflows greatest functions - restartability at any given date.
There is no macro that I know of to get the first day of last month. You could put your calculation function into a small function though - and use context['taskinstance']['execution_date']
and not date.today()
. See more macros here https://airflow.apache.org/code.html#macros
When you have a small function which returns the wanted value, you can add it as your own macro. See more on that in this question: Make custom Airflow macros expand other macros
EDIT
You have tried this:
LAST_MONTH = '{{ (execution_date.replace(day=1) - macros.timedelta(days=1)).replace(day=1) }}'
It is not possible to use standard Python functions within Jinja template strings. Again, I suggest you build a function with one parameter, date, which returns a date as you need it. Then add this function to the available macros with the DAG property user_defined_macros
and use this function like LAST_MONTH = {{ my_date_function_which_gives_my_needed_date(execution_date) }}
More, as stated already, in both links, which also have step-by-step help.