+ 3
Date objects have a replace method, which returns a date object with the newer values you input. The attributes themselves are not changeable. (today.year = 2020 would raise AttributeError) Example: today = datetime.datetime.now().date() year_from_today = today.replace(year=2020) print(year_from_today) # datetime.date(2020, 4, 10)
11th Apr 2019, 2:02 AM
Luis SepĂșlveda
Luis SepĂșlveda - avatar