datefinder icon indicating copy to clipboard operation
datefinder copied to clipboard

Error in parsing date of format dd/mm/yyyy

Open pawankg opened this issue 7 years ago • 5 comments

While using different dates of format dd/mm/yyyy, I see that it is behaving differently as shown in below example:

Case I:

import datefinder

[i for i in datefinder.find_dates('19/04/2018')]
[datetime.datetime(2018, 4, 19, 0, 0)]

In this case I, it is extracting year = 2018, month = 4 and day = 19 as expected.

Case II:

[i for i in datefinder.find_dates('05/04/2018')]
[datetime.datetime(2018, 5, 4, 0, 0)]

But in case II, it is extracting year = 2018, month = 5 and day = 4 (swapped the value of day and month) but it should have been, month = 4 and day = 5.

pawankg avatar May 07 '18 12:05 pawankg

An easy solution is to set a parameter dayfirst=True everywhere parser.parse is called in datefinder.py i.e.: parser.parse(date_string, default=self.base_date, dayfirst=True)

ganevgv avatar Jul 27 '18 15:07 ganevgv

This is a duplicate of #77 and #42

jsenecal avatar Nov 08 '18 19:11 jsenecal

Or you can simply change the init in class class parserinfo(object): in file _parser.py and set datefirst to True

r-deo avatar Sep 06 '20 18:09 r-deo

@pawankg Please try installing the master branch version and let me know if the solution works. There is a new first init option which will let you declare if you want ambiguous dates to be determined by year, month, or day first.

https://github.com/akoumjian/datefinder/blob/master/datefinder/init.py#L23

I haven't yet put it in a pypi release.

akoumjian avatar Sep 07 '20 02:09 akoumjian

@pawankg Please try installing the master branch version and let me know if the solution works. There is a new first init option which will let you declare if you want ambiguous dates to be determined by year, month, or day first.

https://github.com/akoumjian/datefinder/blob/master/datefinder/init.py#L23

I haven't yet put it in a pypi release.

Please release this in pypi

pratiklodha95 avatar Apr 09 '21 08:04 pratiklodha95