Reputation: 4418
the goal is to get month name and year from previous month date. Such: October -2019
But I got an error:
import datetime
d = datetime.date.today()
first_day = d.replace(day=1) # gives first day of current month
last_day = first_day - datetime.timedelta(days=1) # gives last date of previous month
print(last_day.strtime("%B"))
Error:
Traceback (most recent call last):
File "x:\Documents\Python\tempCodeRunnerFile.py", line 7, in <module>
print(last_day.strtime("%B"))
AttributeError: 'datetime.date' object has no attribute 'strtime'
Upvotes: 1
Views: 5371