You can use a timedelta
object:
from datetime import datetime, timedelta
d = datetime.today() - timedelta(days=days_to_subtract)
Related Contents:
- Convert date to datetime in Python
- How do I get the day of week given a date?
- How to print a date in a regular format?
- How to calculate number of days between two given dates
- Adding days to a date in Python
- Creating a range of dates in Python
- Iterating through a range of dates in Python
- How do I get a value of datetime.today() in Python that is “timezone aware”?
- Get month name from number
- In Python, how do you convert seconds since epoch to a `datetime` object?
- Formatting “yesterday’s” date in python
- Python datetime – setting fixed hour and minute after using strptime to get day,month,year
- Cleanest and most Pythonic way to get tomorrow’s date?
- Python – Get Yesterday’s date as a string in YYYY-MM-DD format
- How do I sort a list of datetime or date objects?
- Check if string has date, any format
- Find the end of the month of a Pandas DataFrame Series
- Get Day name from Weekday int
- Convert numpy.datetime64 to string object in python
- User-friendly time format in Python?
- Find the closest date to a given date
- how to get the same day of next month of a given day in python using datetime
- How to set a variable to be “Today’s” date in Python/Pandas
- How would I compute exactly 30 days into the past with Python (down to the minute)?
- How to format date string via multiple formats in python
- Get seconds since midnight in Python [closed]
- Convert Gregorian (Christian) date to Persian date and vice-versa in Python
- Checking date against date range in Python
- Splitting timestamp column into separate date and time columns
- Generate a list of datetimes between an interval
- ValueError: unconverted data remains: 02:05
- How to print current date on python3?
- Convert JSON date string to Python datetime
- Comparing two date strings in Python [duplicate]
- get the last sunday and saturday’s date in python
- Extracting just Month and Year separately from Pandas Datetime column
- Python speed testing – Time Difference – milliseconds
- What exactly does the T and Z mean in timestamp?
- Get date from week number
- get UTC timestamp in python with datetime
- pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset
- Locale date formatting in Python
- python pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working
- Troubleshooting “descriptor ‘date’ requires a ‘datetime.datetime’ object but received a ‘int'”
- How do I remove the microseconds from a timedelta object?
- How to add delta to python datetime.time?
- How do you convert a datetime/timestamp from one timezone to another timezone?
- unexpected results converting timezones in python
- Convert Pandas Series to DateTime in a DataFrame
- pytz utc conversion