I am trying to add the following restrictions to the input date:
- the format has to be ("%d/%m/%Y")
- input date has to be one year < than the actual year
What I did:
from datetime import datetime
date1 = datetime.today().strftime("%d/%m/%Y")
day1, month1, year1 = date1.split("/")
BD = input("Enter your date of birth (format: DD/MM/YYYY): ")
while BD != "%d/%m/%Y": #<------------------------ does not stop if correct format
print("Error")
BD = input("Enter your date of birth (format: DD/MM/YYYY): ")
datetime.strptime(BD, "%d/%m/%Y")
day, month, year = BD.split("/")
while year1 < year:
print("Birthday must be less than current year format has to be DD/MM/YYYY")
BD = input("Enter your date of birth: ")
I have tried with .strftime(x, "%d/%m/%Y") but then it asked the input to be int and if I declared it, gave me an error because I guess it can not turn /'s to int. I tried so many things but I'm sure I'm missing some small thing! If anyone could help me with this, or just show me the simplest way, it would be cool! Thanks!