I'm using time_marker = {{execution_date.in_timezone('Europe/Amsterdam')}} in my dag.py program. I'm trying to keep the date part in execution date, and set the time to "T00:00:00"
So whenever during the execution date it runs, the time_marker will always be for example 20240115T00:00:00
How should I do this? I tried to use pendulum.parse but didn't work out how to do this. Thanks.
Add a custom macro to the DAG definition
Function:
def format_execution_date(execution_date):
amsterdam_time = execution_date.in_timezone('Europe/Amsterdam')
midnight_amsterdam_time = amsterdam_time.start_of('day')
return midnight_amsterdam_time.format('YYYYMMDDT00:00:00')
Use function:
with DAG(
...
user_defined_macros={'format_execution_date': format_execution_date},
) as dag:
...
In your task, you can used by:
params={
'time_marker': '{{ format_execution_date(execution_date) }}'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With