To get the date of yesterday in Python, you can use the datetime
module. Here's an example code:
main.py97 chars5 lines
In this code, we first import the datetime
module. Then, we use the datetime.date.today()
function to get the current date and subtract datetime.timedelta(days=1)
to get the date of yesterday.
The timedelta
function allows you to specify a duration, in this case, 1 day. Subtracting this duration from the current date gives you the date of yesterday.
Finally, we print the yesterday
variable to display the date of yesterday.
gistlibby LogSnag