Code:
from datetime import datetime
date_string ="01-Jun-2020"
date_object = datetime.strptime(date_string, "%d %m, %Y")
print("---date_object =", date_object)
print("---type of date_object =", type(date_object))
Error:
formattedDate : 2021, 15 Feb
Traceback (most recent call last):
File "C:\Users\admin\PycharmProjects\pythonProject\datetimep\dt.py", line 3, in <module>
date_object = datetime.strptime(date_string, "%d %B, %Y")
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\_strptime.py", line 15, in <module>
import calendar
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\calendar.py", line 50, in <module>
class _localized_month:
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\calendar.py", line 52, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\calendar.py", line 52, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
Changed it to
from datetime import datetime
date_string ="01-06-2020"
date_object = datetime.strptime(date_string, "%d %m, %Y")
print("---date_object =", date_object)
print("---type of date_object =", type(date_object))
Instructor
09914040666 Replied on 16/02/2021
Hey,
By changing is it running?