Aryan PrajapatKnowledge Contributor
Write a Python program to find yesterday’s, today’s and tomorrow’s date.
Write a Python program to find yesterday’s, today’s and tomorrow’s date.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
from datetime import datetime, timedelta
def get_dates():
# Get today’s date
today = datetime.now().date()
# Calculate yesterday’s and tomorrow’s date
yesterday = today – timedelta(days=1)
tomorrow = today + timedelta(days=1)
return yesterday, today, tomorrow
# Get the dates
yesterday_date, today_date, tomorrow_date = get_dates()
# Display the dates
print(“Yesterday’s date:”, yesterday_date)
print(“Today’s date:”, today_date)
print(“Tomorrow’s date:”, tomorrow_date)
This program uses the datetime module to work with dates. It defines a function get_dates() to calculate yesterday’s, today’s, and tomorrow’s dates using timedelta objects. Then, it calls this function and prints the dates accordingly.