I have to ask the user to enter a start date and an end date. The date has to be in YYYY-MM-DD format. And I have already wrote some if statements that handle some formatting errors that the user might make, such as not inputting dashes in between, and also inputting the months and days in each other's spots.
What I need now is a way to make sure that the end date will always be later than the start date. Since logically an end date can't happen before the start date.
I don't know of a way to do this. Any help would be appreciated, thanks.
def get_start_date() -> str:
START_DATE = input('Enter start date (in YYYY-MM-DD format): ').strip()
if len(START_DATE) != 10:
print('Date entry not correct, please try again')
get_start_date()
elif eval(START_DATE[5]) > 1:
print('Date entry not correct, please try again')
get_start_date()
elif eval(START_DATE[8]) > 3:
print('Date entry not correct, please try again')
get_start_date()
elif START_DATE[4] and START_DATE[7] != '-':
print('Date entry not correct, please try again')
get_start_date()
def get_end_date() -> str:
END_DATE = input('Enter end date (in YYYY-MM-DD format): ').strip()
if len(END_DATE) != 10:
print('Date entry not correct, please try again')
get_end_date()
elif END_DATE[4] and END_DATE[7] != '-':
print('Date entry not correct, please try again')
get_end_date()
elif eval(END_DATE[5]) > 1:
print('Date entry not correct, please try again')
get_end_date()
get_start_date()
get_end_date()