Created
          January 16, 2010 02:10 
        
      - 
      
- 
        Save luispedro/278594 to your computer and use it in GitHub Desktop. 
    Parse a date
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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