How to get yesterday’s date in Python

Getting yesterday’s date returns a datetime.date object representing yesterday’s date.

Solution for How to get yesterday’s date in Python : You can use datetime.timedelta() to get yesterday’s date Call datetime.date.today() to get today’s date in local time. Use today – datetime.timedelta(days=1) to subtract one day from the previous result today.

Use datetime.datetime.utcnow().date() instead of datetime.date.today() to use UTC time instead of local time.

today = datetime.datetime.utcnow().date()


how-to-get-yesterday-s-date-in-python