Python Date and time, I am getting attribute error | Selenium Python Forum
N
Nitika Posted on 16/10/2020
 

Using the same code as mentioned but still getting error for strptime.Check attached screenshot


0
09914040666 Replied on 16/10/2020

Hey 

Kindly please share your code so that it could be checked.


N
Nitika Replied on 16/10/2020

 
from _datetime import datetime

currentdate = datetime.now()
print(currentdate)
print(type(currentdate))

formattedDate = currentdate.strftime("%Y,%d %b")
print(formattedDate)
date = "28/09/2020"
string_formattedDate = datetime.strptime(date, "%d/%m/%Y")
print(string_formattedDate)


0
09914040666 Replied on 16/10/2020

Hey

Your code is absolutely fine. The error that you are getting is because of the module name. Do not give the module names as same as the exisiting keywords otherwise interpreter starts searching for the attribute in the module made by you. Kindly change the name of your module to something other than datetime, it will run fine.


N
Nitika Replied on 17/10/2020

 

Sorry I did not get your point, where I need to change the module name, if I am changing datetime module name then it showing me error.Can you please share code for this.

from _datetime import datetime

currentdate = datetime.now()
print(currentdate)
print(type(currentdate))

formattedDate = currentdate.strftime("%Y,%d %b")
print(formattedDate)
date = "28/09/2020"
string_formattedDate = datetime.strptime(date, "%d/%m/%Y")
print(string_formattedDate)

where I need to change?


0
09914040666 Replied on 17/10/2020

Hey

The code is correct, the name of the file is to be changed. You have the filename for this code as "datetime", change it to something else.


N
Nitika Replied on 18/10/2020

 

okay, issue has been resolved.Thanks


0
09914040666 Replied on 20/10/2020

Hey

Thank you for the update.


Related Posts