defrex defrex - 3 months ago 14
Python Question

How can I subtract a day from a Python date?

I have a Python

object. What is the best way to subtract one day?

Answer

You can use a timedelta object:

from datetime import datetime, timedelta

d = datetime.today() - timedelta(days=days_to_subtract)