In [3]: import datetime as dt
In [4]: today=dt.date.today()
In [5]: three_years_ago=today-dt.timedelta(days=3*365)
In [6]: three_years_ago
Out[6]: datetime.date(2008, 3, 1)
This works to cater for leap year corner cases and non-leap years too. Because, if day = 29 and month = 2 (Feb), a non-leap year would throw a value error because there is no 29th Feb and the last day of Feb would be 28th, thus doing a -1 on the date works in a try-except block.
from datetime import datetime
last_year = datetime.today().year - 1
month = datetime.today().month
day = datetime.today().day
try:
# try returning same date last year
last_year_date = datetime.strptime(f"{last_year}-{month}-{day}",'%Y-%m-%d').date()
except ValueError:
# incase of error due to leap year, return date - 1 in last year
last_year_date = datetime.strptime(f"{last_year}-{month}-{day-1}",'%Y-%m-%d').date()
print(last_year_date)