I want to check using Python if a random date provided is ambiguous or not.
For instance. 3/7/91. This could be March 7, XX91 or 3 July XX91. Thus, ambiguous.
My logic is - If the day & month both lie in the range of 1-12, then 'Day' & 'Month' are ambiguous. Also, if the 'Year' has only two digits, then its value is ambiguous.
This is what I've tried -->
Steps: 1) Mention the date
2) Split the date
3) Mention different combinations of date formats
4) If date format is the same but only with a difference in the separator &
the date & month have a value between 1-12 & the year contains only 2
digits, then the date is ambiguous, else, not.
What I have tried:
date="3/19/1991"
dmy_split=""
dmy_split=date.split('/, -')
date_formats = ['%d/%m/%Y','%m/%d/%Y','%Y/%m/%d','%d-%m-%Y','%m-%d-%Y', '%Y-%m-%d']
if (date_formats==date_formats[0] or date_formats==date_formats[3]):
if (dmy_split[0] in range (1,13) and dmy_split[1] in range (1,13) or len(dmy_split[2])==2):
print("ambiguous")
else:
print("not ambiguous")
Issue: The result is always "not ambiguous". My logic seems right. Please let me know where I've gone wrong.