Question: how to calculate difference between two dates in years in python?
Answer: datetime1 = datetime. datetime(2000, 1, 1) datetime2 = datetime. datetime(2010, 1, 1) time_difference = relativedelta(datetime2, datetime1) difference_in_years = time_difference. years. print(difference_in_years, "years")