Adding days to a date in Python

Adding days to a date in Python

The previous answers are correct but its generally a better practice to do:

import datetime

Then youll have, using datetime.timedelta:

date_1 = datetime.datetime.strptime(start_date, %m/%d/%y)

end_date = date_1 + datetime.timedelta(days=10)

Import timedelta and date first.

from datetime import timedelta, date

And will return todays datetime, may be you want

EndDate = + timedelta(days=10)

Adding days to a date in Python

If you happen to already be using pandas, you can save a little space by not specifying the format:

import pandas as pd
startdate = 10/10/2011
enddate = pd.to_datetime(startdate) + pd.DateOffset(days=5)

Leave a Reply

Your email address will not be published. Required fields are marked *