The timedelta
object from the datetime
module allows you to subtract any number of days from a date object.
In this example I always take the current date using the date.today()
method.
Then I set a timedelta
of 2 days and subtract it from the current_date
.
from datetime import timedelta, date
current_date = date.today()
print(current_date)
past_date = current_date - timedelta(days=2)
print(past_date)
2020-04-27
2020-05-25