defrex defrex -4 years ago 175
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 Source

You can use a timedelta object:

from datetime import datetime, timedelta

d = - timedelta(days=days_to_subtract)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download