We have some legacy string dates that I need to convert to actual dates that can be used to perform some date logic. Converting to a date object isn't a problem if I knew what the format were! That is, some people wrote 'dd month yy', othes 'mon d, yyyy', etc.
So, I was wondering if anybody knew of a py module that attempts to guess date formats and rewrites them in a uniform way?
Any other suggestions?
Thanks! :)
Eric
The typical approach is to define a list of formats (
strptime
formats, specifically), and try them in turn, until one works. As an example, see this recipe:http://code.activestate.com/recipes/577135-parse-a-datetime-string-to-a-datetime-instance/
strptime
accepts quite a number of formats. If you can enumerate all the possibilities you'll see, you should be able to hack together a variant of that recipe that'll do what you want.