I'm am trying to validate a string
prompted for the user. This string
should be write in the format dd/mm/aaaa
and be a valid date. I thought than create a lot of if
to check is not be ellegant, so i research and picked-up the datetime
way.
import datetime
dataInput = input("Insira sua data de nascimento no formato 'dd/mm/aaaa': ")
ehDataValida = False
def validaData(dataInput) :
while True :
try :
if dataInput != datetime.datetime.strptime(dataInput, "%d/%m/%Y").strftime("%d/%m/%Y") :
raise ValueError
return False
except ValueError:
print("erro!")
dataInput = input("Insira sua data de nascimento no formato 'dd/mm/aaaa': ")
return dataInput
validaData(dataInput)
print(validaData(dataInput))
It's not working and for each test I found a new bug. What i'm missing? After this, I will dataInput.split('/')
and achieve the date in a listData=[dd, mm, yyyy]