How to get yesterday date in Python?

How to get yesterday date in Python?


How to get yesterday date in Python?


In this example, I will show you how to get yesterday date in python. we will implement a python get yesterday date.

let’s see below example code and try it.

from datetime import datetime, timedelta

today = datetime.now()

yesterday = today - timedelta(1)
tomorrow = today + timedelta(1)

print("Yesterday Date :", yesterday.strftime('%d-%m-%Y))
print("Today Date :", today.strftime('%d-%m-%Y))
print("Tomorrow Date :", tomorrow.strftime('%d-%m-%Y))


Yesterday Date : 28-06-2022
Today Date :  29-06-2022
Tomorrow Date : 30-06-2022

I hope you like this article.

Also Read :