Search code examples
pythonpython-3.xdateparser

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?


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))]