epam_diplom/check_date.py

28 lines
767 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from datetime import datetime, date
def check_date(input_date):
try:
datetime.strptime(input_date, '%Y-%m-%d').date()
return True
# valid_date = datetime.strptime(input_date, '%Y-%m-%d').date()
# if valid_date < date.today():
# return True
# else:
# print('Введенная дата еще не наступила')
# return False
except ValueError:
return False
while True:
input_day = input('Введите дату в формате ГГГГ-ММ-ДД): ')
if check_date(input_day):
print('Введенная дата корректна')
break
else:
print('Введенная дата некорректна')
continue