13

I'm looking for a Python module that would take an arbitrary block of text, search it for something that looks like a date string, and build a DateTime object out of it. Something like Date::Extract in Perl

Thank you in advance.

2 Answers 2

12

The nearest equivalent is probably the dateutil module. Usage is:

>>> from dateutil.parser import parse
>>> parse("Wed, Nov 12")
datetime.datetime(2008, 11, 12, 0, 0)

Using the fuzzy parameter should ignore extraneous text. ie

>>> parse("the date was the 1st of December 2006 2:30pm", fuzzy=True)
datetime.datetime(2006, 12, 1, 14, 30)
1
  • This is better than parsedatetime, but the input string can only have a single date in it.
    – mlissner
    Commented Aug 11, 2011 at 15:24
5

Why no give parsedatetime a try?

1
  • I took a look at this. On their todo: "Ability to scan large parts of text and extract any found date/time information". That kind of rules it out for me.
    – mlissner
    Commented Aug 11, 2011 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.