Skip to content

Instantly share code, notes, and snippets.

@luispedro
Created January 16, 2010 02:10
Show Gist options
  • Save luispedro/278594 to your computer and use it in GitHub Desktop.
Save luispedro/278594 to your computer and use it in GitHub Desktop.
Parse a date
import time
def parsedate(daterep):
'''
time = parsedate(daterep)
Parses a date written out in English.
'''
formats = ['%d %b %Y', '%d %B %Y', '%b %d %Y', '%B %d %Y']
for f in formats:
try:
return time.strptime(daterep, f)
except:
pass
raise ValueError("Cannot parse '%s' as a date" % daterep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment