Try each format and see if it works:
from datetime import datetime
def try_parsing_date(text):
for fmt in ('%Y-%m-%d', '%d.%m.%Y', '%d/%m/%Y'):
try:
return datetime.strptime(text, fmt)
except ValueError:
pass
raise ValueError('no valid date format found')
from : https://stackoverflow.com/questions/23581128/how-to-format-date-string-via-multiple-formats-in-python
No comments:
Post a Comment