You can use a timedelta
object:
from datetime import datetime, timedelta
d = datetime.today() - timedelta(days=days_to_subtract)
More Related Contents:
- How to print a date in a regular format?
- How to calculate number of days between two given dates
- Iterating through a range of dates in Python
- How do I get the day of week given a date?
- Creating a range of dates in Python
- Adding days to a date in Python
- Convert Excel style date with pandas
- How do I get a value of datetime.today() in Python that is “timezone aware”?
- Get month name from number
- Find the end of the month of a Pandas DataFrame Series
- How to format date string via multiple formats in python
- In Python, how do you convert seconds since epoch to a `datetime` object?
- Check if string has date, any format
- Find the closest date to a given date
- Generate a list of datetimes between an interval
- Splitting timestamp column into separate date and time columns
- Extract day of year and Julian day from a string date
- Convert numpy.datetime64 to string object in python
- Comparing two date strings in Python
- Convert date to datetime in Python
- Which is the fastest way to extract day, month and year from a given date?
- Formatting “yesterday’s” date in python
- Keep a datetime.date in ‘yyyy-mm-dd’ format when using Flask’s jsonify
- Clean way to convert quarterly periods to datetime in pandas
- How to combine year, month, and day columns to single datetime column?
- How do I convert timestamp to datetime.date in pandas dataframe?
- Convert dates to pd.to_datetime where month could be either a number or month name
- datetime from string in Python, best-guessing string format
- need to convert UTC (aws ec2) to PST in Python
- Pandas: select all dates with specific month and day