How can I subtract or add 100 years to a datetime field in the database in Django?

I would use the relativedelta function of the dateutil.relativedelta package, which will give you are more accurate ‘n-years ago’ calculation:

from dateutil.relativedelta import relativedelta
import datetime

years_ago = datetime.datetime.now() - relativedelta(years=5)

Then simply update the date field as others have shown here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)