I have an issue with my Python code which works on Windows XP (Python 2.7):
from datetime import datetime
from datetime import date
def temps_valide(nbrjmax):
try:
datetime.strptime(nbrjmax, '%d/%m/%Y')
return True
except ValueError:
return False
def nbrjour(nbrjmax):
date_aujoudhui = datetime.now().date()
delta = date_aujoudhui - format_date_ent
return delta.days
boucle = "2"
while boucle == "2":
test = "test"
if test == "test":
nbrjmax = input("Date (JJ/MM/AAAA) ? : ")
while temps_valide(nbrjmax) == False:
print("Entrez un format correct (JJ/MM/AAAA)")
nbrjmax = input("Date (JJ/MM/AAAA)? : ")
else:
format_date_ent = datetime.strptime(nbrjmax, '%d/%m/%Y').date()
nbrjmax = nbrjour(nbrjmax)
else:
nbrjmax = 0
print(nbrjmax)
With Python 3.9, this code works perfectly but not on 2.7 version.
When I add str(nbrjmax)
on the function temps_valide
, I'm stuck in the while loop, like the verify don't work.