I know you can use DateObject[{"05-08-2022", {"Day", "Month", "Year" }}]
to tell WL the date format explicitly, but a rigid format is often inadequate for interpreting dates from messy sources (such as TextCases
) where you don't know exactly in advance what you're going to find. You could end up with dates like:
dates = {
"05-08-2022", "2 June 1999", "March 5th 2001",
"2022-04-03", "2021-02-11T15:30"
}
Using DateObject[{date, format}]
will not work here, but just vanilla DateObject /@ dates
almost does the right thing. Unfortunately, though, you can't just tell DateObject
to interpret "05-08-2022"
as mm-dd-yyyy in case of ambiguity. Instead, it uses your locale to infer your preferred date format and uses that, which is not what you may always want.
How do you extend this auto-magic functionality of DateObject
(or Interpreter["Date"]
) so you can tell it you want day-first or month-first interpretations for edge cases?