I am working on a project in which I need to use datetime, timedelta, strftime, and strptime.
To get this to work my imports look like this:
from datetime import datetime, timedelta
import datetime as dt
The code starts with taking in two string dates: ‘05/11/21’, ‘05/13/21’
It then uses datetime.strptime to convert these into datetime dates and generates a list of dates between them, it outputs this list:
date_list = [datetime.datetime(2021, 5, 11, 0, 0), datetime.datetime(2021, 5, 12, 0, 0), datetime.datetime(2021, 5, 13, 0, 0)]
Now I want to iterate through that list and turn the datetimes back into strings.
date_string = []
for d in date_list:
date_string += datetime.strftime(d, '%m/%d/%y')
print(date_string)
I get this error:
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'.
Please help, Thanks so much