To subtract one day from the current date in Python using the datetime
module, you can use the date.today()
function along with the timedelta
function. Here's an example:
main.py137 chars7 lines
In the above code, date.today()
returns the current date as a date
object, and timedelta(days=1)
creates a time delta of one day. Subtracting this time delta from the current date gives you the previous day's date.
Running the code will output the previous date in the format YYYY-MM-DD
.
gistlibby LogSnag