How to Get Yesterday Date in Python?
By Hardik Savani
•
October 30, 2023
Python
In this example, I will show you how to get yesterday date in python. In this article, we will implement a python get yesterday date. I would like to show you python find yesterday's date. I would like to share with you python3 get yesterday date example.
In this example, i will show you how to get today's date, tomorrow's date and yesterday's date. therefore, let's see below example code and try it.
Example:
main.py
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'))
Output:
Read Also: How to Get Current Second in Python?
Yesterday Date : 06-06-2022 Today Date : 07-06-2022 Tomorrow Date : 08-06-2022
I hope it can help you...