Parsing text into dates?

John Machin sjmachin at lexicon.net
Mon May 16 21:07:13 EDT 2005


On 16 May 2005 17:51:31 -0700, "George Sakkis" <gsakkis at rutgers.edu>
wrote:


>#=======================================================
>
>def parseDateTime(string, USA=False, implyCurrentDate=False,
>                  yearHeuristic=_20thcenturyHeuristic):
>    '''Tries to parse a string as a valid date and/or time.
>
>    It recognizes most common (and less common) date and time formats.

Impressive!


>
>    Examples:
[snip]
>        >>> str(parseDateTime('15.6.2001'))
>        '2001-06-15'
>        >>> str(parseDateTime('6.15.2001'))
>        '2001-06-15'

A dangerous heuristic -- 6.12.2001 (meaning 2001-12-06) can be easily
typoed into 6.13.2001 or 6.15.2001 on the numeric keypad.





More information about the Python-list mailing list