;

How to Find Yesterday’s, Today’s and Tomorrow’s date in Python


Tutorialsrack 29/04/2020 Python

In this article, we will learn how to find yesterday's, today’s, and tomorrow’s date in python. We will use the datetime.today() to get the current date from the datetime module. And timedelta class is used to manipulate the date by incrementing or decrementing the days by 1 from today’s date to get the yesterday and tomorrow date.

Here is the source code of the program to find yesterday's, today’s, and tomorrow’s date in python.

How to Find Yesterday’s, Today’s and Tomorrow’s date in Python
# How to Find Yesterday’s, Today’s and Tomorrow’s date in Python

# Import Module
import datetime

# Today's Date
today = datetime.date.today()

# Yesterday's Date
yesterday = today - datetime.timedelta(days = 1)

# Tomorrow's Date
tomorrow = today + datetime.timedelta(days = 1)

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

Yesterday's Date:  28-04-2020

Today's Date:  29-04-2020

Tomorrow's Date:  30-04-2020

I hope this article will help you to understand how to find yesterday's, today’s, and tomorrow’s date in python.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags