How to subtract a day from a date?

defrex picture defrex · Jan 13, 2009 · Viewed 658k times · Source

I have a Python datetime.datetime object. What is the best way to subtract one day?

Answer

Steve B. picture Steve B. · Jan 13, 2009

You can use a timedelta object:

from datetime import datetime, timedelta
    
d = datetime.today() - timedelta(days=days_to_subtract)