In regular python code I can do:
import time
int(time.time())
This gives me the time as epoch.
I want to be able to do this with airflow macro: execution_date
This is what I tried:
"{{ strptime(execution_date.strftime('%Y-%m-%d %H:%M:%S'), '%d.%m.%Y %H:%M:%S') }}"
But this gives:
jinja2.exceptions.UndefinedError: 'strptime' is undefined
I'm running Airflow 1.9 & Python 2.7
Since Airflow 1.10, Airflow uses Pendulum for datetimes, which has attributes timestamp(), int_timestamp and float_timestamp which return the epoch.
So, you could do:
{{ execution_date.int_timestamp }}
Docs: https://pendulum.eustace.io/docs/#attributes-and-properties
Other options are:
{{ execution_date.strftime('%s') }} # Also Python 2
{{ execution_date.timestamp() }} # Python >=3.3
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