I have a Python datetime.datetime
object. What is the best way to subtract one day?
Therefore, you can add or subtract days as easy as adding or minus the number of days in Excel. 1. Select a blank cell you will place the calculating result, type the formula =A2+10, and press the Enter key. Note: For subtracting 10 days from the date, please use this formula =A2–10.
You can use d. setDate(d. getDate() + days) with both positive and negative values for days to add and subtract days respectively. And it should work on the instance (as other Date methods do), not create and return a copy.
Following the answer from Philip Rego, you can use SELECT GETDATE() - 1 to subtract days from a date.
You can use a timedelta
object:
from datetime import datetime, timedelta d = datetime.today() - timedelta(days=days_to_subtract)
Subtract datetime.timedelta(days=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With