R has a very nice workflow that allows user to set the date/month/year order but otherwise handles messiness of user-input date strings:
date_str = c('05/03/2022', '14/03/2022', '14.03.2022', '14/03.2022')
lubridate::parse_date_time(date_str, orders = 'dmy')
#> [1] "2022-03-05 UTC" "2022-03-14 UTC" "2022-03-14 UTC" "2022-03-14 UTC"
The closest I've found in Python is:
from dateparser import parse
date_str = ['05/03/2022', '14/03/2022', '14.03.2022', '14/03.2022']
list(map(lambda l: parse(l, date_formats = ['dmy']), date_str))
[datetime.datetime(2022, 5, 3, 0, 0),
datetime.datetime(2022, 3, 14, 0, 0),
datetime.datetime(2022, 3, 14, 0, 0),
datetime.datetime(2022, 3, 14, 0, 0)]
which handles messiness but transposes day/month in the first observation, I think because date_formats prioritises explicitly defined formats and otherwise reverts to the (silly) default US month-day-year format?
Is there a nice implementation in Python that can be relied upon to handle messiness as well as assume a date/month ordering?