You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to be impossible to get the following behaviour: parse("01-02-03") == "datetime.datetime(2003, 2, 1, 0, 0)" parse("2003-02-01") == "datetime.datetime(2003, 2, 1, 0, 0)"
The problem is that when ever the first line evaluates true, then the second line will produce a date where day and month is swapped (like so datetime.datetime(2003, 1, 2, 0, 0))
This is the preferred way of parsing dates in all northern european countries btw.
The choice of MDY format as default one has been discussed before. I'll bring back the core argument (backed by general observations, not data) that the default date settings on most web servers are still English (United States).
The reason why I would like to use the dateparser library is because I don't know the date format. Your workaround will fail on the first example ("01-02-03").
date_formats list can be extended, so: parse("01-02-03", date_formats=["%Y-%m-%d", "%d-%m-%y"])
But I understand that if you have a multitude of formats, a setting that doesn't work is a serious limitation.
However, as it turns out, Sweden does their dates differently. They prefer YMD over DMY. Neither pandas or dateutil was abel to handle this use-case using dayfirst and yearfirst. So I guess what I really need is a monthinmiddle setting. Just phrased differently, the dayfirst and yearfirst is just a "broken" interface in my opinion, so don't try to go down that road.
I need to mass parse UK dates, which are DMY (and there's no locale), but I can't if that breaks ISO dates.
People with a date format set in their locale flat out can't read ISO dates without disabling the locale first:
I also have this issue and can confirm it is still present in 1.1.0. A monthmiddle setting seems to be much more relevant than specifying a date order in the many cases when you don't know the format. An alternative would be to accept a list of orders to try. Or another alternative is that if DATE_ORDER is specified, parsing should fail if that order cannot be parsed, so that the user of the library can know and implement their own fallback.
Activity
elgehelge commentedon May 9, 2018
I think the core of the problem is this behaviour:
asadurski commentedon May 9, 2018
Thank you for reporting that, @elgehelge, I have reproduced the problem.
As a temporary workaround, you can use
date_formatsargument, as described in http://dateparser.readthedocs.io/en/latest/index.html#usageparse("2003-02-01", date_formats=["%Y-%m-%d"])The choice of MDY format as default one has been discussed before. I'll bring back the core argument (backed by general observations, not data) that the default date settings on most web servers are still English (United States).
elgehelge commentedon May 9, 2018
The reason why I would like to use the dateparser library is because I don't know the date format. Your workaround will fail on the first example ("01-02-03").
asadurski commentedon May 9, 2018
date_formatslist can be extended, so:parse("01-02-03", date_formats=["%Y-%m-%d", "%d-%m-%y"])But I understand that if you have a multitude of formats, a setting that doesn't work is a serious limitation.
elgehelge commentedon May 9, 2018
Let me just give you a little more insight into the problem. I figured out that pandas would actually work for my use case:
However, as it turns out, Sweden does their dates differently. They prefer YMD over DMY. Neither pandas or dateutil was abel to handle this use-case using
dayfirstandyearfirst. So I guess what I really need is amonthinmiddlesetting. Just phrased differently, thedayfirstandyearfirstis just a "broken" interface in my opinion, so don't try to go down that road.crusaderky commentedon Sep 15, 2020
Any update on this issue? It seems major to me.
I need to mass parse UK dates, which are DMY (and there's no locale), but I can't if that breaks ISO dates.
People with a date format set in their locale flat out can't read ISO dates without disabling the locale first:
fish-face commentedon Jan 16, 2022
I also have this issue and can confirm it is still present in 1.1.0. A
monthmiddlesetting seems to be much more relevant than specifying a date order in the many cases when you don't know the format. An alternative would be to accept a list of orders to try. Or another alternative is that ifDATE_ORDERis specified, parsing should fail if that order cannot be parsed, so that the user of the library can know and implement their own fallback.