Write a Python program to print yesterday, today, tomorrow


This program demonstrates how to use the datetime module to calculate and display the dates of yesterday, today, and tomorrow. First, the program imports the datetime module. Then, it gets the current date using the date.today() method and stores it in the today variable.

Next, the program uses the timedelta function to calculate yesterday's and tomorrow's date by subtracting and adding one day to the current date, respectively. The resulting dates are stored in the yesterday and tomorrow variables. Finally, the program prints the values of yesterday, today, and tomorrow using the print() function along with their respective variable names.

Source Code

import datetime 
today = datetime.date.today()
yesterday = today - datetime.timedelta(days = 1)
tomorrow = today + datetime.timedelta(days = 1) 
print("Yesterday : ",yesterday)
print("Today : ",today)
print("Tomorrow : ",tomorrow)

Output

Yesterday :  2022-09-23
Today :  2022-09-24
Tomorrow :  2022-09-25

Example Programs