I am trying to get a program to check to make sure a string variable "date" is in the correct format YYYY-MM-DD. I attempted this with the code below.
def check_date_format(date):
has_correct_dashes = check_dashes(date)
split_date = date.split('-')
while not has_correct_dashes or (split_date[0]) != 4 or len(split_date[1]) != 2 or \
len(split_date[2]) != 2:
date = input('ERROR: Must follow 1970-01-01 format, try again: ')
has_correct_dashes = check_dashes(date)
split_date = date.split('-')
return date
My problem is that the while loop is never returning true, but I'm not sure why (even when given the correct format).
Thanks