9 ms·
I respect wanting or needing to do this with just the builtin datetime module. For everyone else, I recommend relativedelta from the dateutil package: https://d
by kgabbott 7y ago
I respect wanting or needing to do this with just the builtin datetime module. For everyone else, I recommend relativedelta from the dateutil package: https://dateutil.readthedocs.io/en/stable/relativedelta.html https://dateutil.readthedocs.io/en/stable/relativedelta.html
e.g.:
>>> from dateutil.relativedelta import relativedelta
>>> date = datetime.utcnow().date()
>>> date
datetime.date(2020, 2, 29)
>>> date + relativedelta(years=1)
datetime.date(2021, 2, 28)
- mj1586 7y agoI added to here: https://stackoverflow.com/a/60468711/634824 https://stackoverflow.com/a/60468711/634824 Thanks.