718
In this article we will show you how to find yesterdays date, todays date and tomorrow’s date, the current time is determined, and a method is used that helps find previous day and next day’s dates.
Example
First we import the necessary modules
Then we get todays date using datetime.now()
We then use timedelta to get tomorrows date date and the previous days date.
We then print all of the dates
# import modules from datetime import datetime, timedelta # get todays date presentdate = datetime.now() # work out yesterdays dat yesterday = presentdate - timedelta(1) #get tomorrows date tomorrow = presentdate + timedelta(1) # print the dates print("Yesterday was :") print(yesterday.strftime('%d-%m-%Y')) print("Today is :") print(presentdate.strftime('%d-%m-%Y')) print("Tomorrow would be :") print(tomorrow.strftime('%d-%m-%Y'))
Lets try this example out
>>> %Run todaytommorowyesterday.py Yesterday was : 08-04-2022 Today is : 09-04-2022 Tomorrow would be : 10-04-2022
Link
This is in our github repository