Python Dates¶
Time intervals¶
We can do time delta in days
from datetime import datetime, timedelta
t0 = datetime(year=2022, month=1, day=1)
t1 = datetime(year=2022, month=8, day=11)
diff = t1 - t0
>>> diff
datetime.timedelta(days=222)
>>> diff.total_seconds()
19180800.0
Time delta in days instead of seconds¶
Subtract a month from a date¶
from datetime import date
from dateutil.relativedelta import relativedelta
>>> date.today()
datetime.date(2022, 11, 9)
>>> date.today() - relativedelta(months=1)
datetime.date(2022, 10, 9)
Last update:
2023-04-24