Datetime does not recognize strftime

Asked

Viewed 26 times

-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)```
  • 1

    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

  • 1

    The module datetime has the class datetime, then it should be datetime.datetime.strptime <-- note also that I used strptime ("p" instead of "f", because you want to convert a string to date - strftime does the opposite). And data_convertida is a variable that you created, does not belong to the module, so you do not need to datetime. for access: https://ideone.com/5AFkAs

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.