Hi,
I have a big search field, where users could type in any peice of text and it would search for it.
Now I have a requirement to add in dob to my search. I am not adding a new textbox with a dob picker. I just want users to be able to input a dob in a range of formats and it would figure it out.
IE users can search using any combination of these:
- 25/08/1970
- 25-08-1970
- 1970/08/25
- 1970-08-25
My program must figure out the dmy for each.
Is there a better way?
def parse(dob):
for d in dob.split(" "):
# find the dob
if len(d) == 10:
# its a dob
if d[0:4].isdigit() # this is the year
year = d[0:4]
month = d[5:7]
day = d[8:10]
elif d[6:10].isdigit() # this is the year
day = d[0:2]
month = d[3:5]
year= d[6:10]