Home > Back-end >  find previous sunday date based on today date in Django
find previous sunday date based on today date in Django

Time:11-09

Let us consider today date as 09/11/2021

And previous sunday date is 31/10/2021

today = datetime.date.today()

Now find previous sunday date

CodePudding user response:

You can use relativedelta from dateutil.

from dateutil.relativedelta import relativedelta, SU
last_sunday = date.today()   relativedelta(weekday=SU(-1))

CodePudding user response:

last_sunday = today - datetime.timedelta(days=today.weekday()   8)
  • Related