-1
I’m trying to make a code that receives a date in the format of String, this way '2021-8-24', year month day, but I will convert to date, only the terminal speaks:
data_converted = datetime.strftime(data_withdrawal, '%Y-%m-%d'). date() Attributeerror: module 'datetime' has no attribute 'strftime'
Ignore the last two lines I was trying to convert from YYYY-MM-DD to DD-MM-YYYY
is already searched in the documentation, is the strftime, is part of datetime and do not know how to solve this problem
import datetime
data_retirada = '2021-8-24'
hora_retirada = '13-12'
data_convertida = datetime.strftime(data_retirada, '%Y-%m-%d').date()
print(data_convertida)
print(type(data_convertida))
year = datetime.data_convertida.year
print(year)```
These are simple and specific errors, so I’m not going to give you an answer. But look at your corrected code: https://ideone.com/UdU7D6
– Augusto Vasques
The module
datetime
has the classdatetime
, then it should bedatetime.datetime.strptime
<-- note also that I usedstrptime
("p" instead of "f", because you want to convert a string to date -strftime
does the opposite). Anddata_convertida
is a variable that you created, does not belong to the module, so you do not need todatetime.
for access: https://ideone.com/5AFkAs– hkotsubo