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
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)I added to here:
https://stackoverflow.com/a/60468711/634824
Thanks.
I was about to ask why you didn't use a timedelta, and then found out that datetime.timedelta doesn't support anything greater than week.
It also has this incorrect example: https://docs.python.org/3/library/datetime.html#examples-of-...
https://git.sr.ht/~sircmpwn/meta.sr.ht/commit/e0be9dcd8e96f9...