Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Troubles with python dateparser

I am using dateparser and i have got a case, when in the string with date there are other words and I have detected that it doesn’t return expected result in this case.

from dateparser import parse

print(parse('April 19, 2006')) # returns 2006-04-19 00:00:00
print(parse('April 19, 2006 test test')) # returns None

How it works?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As documentation has already warned

Support for searching dates is really limited and needs a lot of improvement, we look forward to community’s contribution to get better on that part

it’s better not to use it that way. but there’s a function for this case. try

from dateparser.search import search_dates
print(search_dates('April 19, 2006 test test'))

output:

[('April 19, 2006', datetime.datetime(2006, 4, 19, 0, 0))]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading