views:

224

answers:

3

I can't remember which application I was using, but I do recall it having really neat date parsing/interpretation.

For example, you could type in 'two days ago' or 'tomorrow' and it would understand.

Any libraries to suggest? Bonus points if usable from Python.

+3  A: 

Perhaps you are thinking of PHP's strtotime() function, the Swiss Army Knife of date parsing:

Man, what did I do before strtotime(). Oh, I know, I had a 482 line function to parse date formats and return timestamps. And I still could not do really cool stuff. Like tonight I needed to figure out when Thanksgiving was in the US. I knew it was the 4th Thursday in November. So, I started with some math stuff and checking what day of the week Nov. 1 would fall on. All that was making my head hurt. So, I just tried this for fun.

strtotime("thursday, november ".date("Y")." + 3 weeks")

That gives me Thanksgiving. Awesome.

Would you believe it even has its own dedicated web site, www.strtotime.net?

Sadly, there does not appear to be a Python equivalent. The closest thing I could find is the dateutil.parser module.

John Kugelman
+2  A: 

The simple one I have seen for python is here.

It uses pyparsing and is only a small script, but it does what you ask. However, the advantage being it would be pretty easy to extend and improve on if needed. Pyparsing is relatively easy to learn as parsing goes.

David Raznick
+3  A: 

See my SO answer for links to three Python date parsing libraries. The one of these most commonly used is python-dateutils but unfortunately it can't handle all formats.

Van Gale