Search code examples
pythondate-formattingpython-datetime

Parse this date in Python: 5th November 2010


I'm having a bad time with date parsing and formatting today.

Points for somebody who can parse this date format into a datetime.date or datetime.datetime (I'm not too fussy but I'd prefer .date):

5th November 2010


Solution

  • Using dateutil:

    In [2]: import dateutil.parser as dparser
    
    In [3]: date = dparser.parse('5th November 2010')
    
    In [4]: date
    Out[4]: datetime.datetime(2010, 11, 5, 0, 0)