df = pd.read_csv(dataname, sep=',')
# get rid of the format issue
df.rename(columns={df.columns[0]: 'Date' }, inplace=True)
# select desired columns
df = df[['Date', 'Close']]
# define your format in the Date column
date_format = '%Y-%m-%d'
#initialize an empty string
numdays=['ha'] #need to add a column title
# select the first date
date1 = datetime.strptime(df['Date'][len(df['Date'])-1], date_format)
for i in range(0,len(df['Date'])):
# select the second date
date2 = datetime.strptime(df['Date'][i], date_format)
# calculate the difference between the dates
diffDates = date2 - date1
numdays.append(diffDates.days) #numb of days between two given dates
# calculate the difference between the dates
diffDates = date2 - date1
Above is what i have to determine the number of days between two given dates.
Now, I'd like to do the opposite.
Suppose you know how many days have passed since 1/03/2008 for example,
Is there a simple way in Python to find out what month/day/year it is now? given the number of days between 1/03/2008 and now?