python get and convert to date from string
Question: I want to convert the following string to date in python ,how to go about
this,

    
    
    >>> d= "1997-01-29 00:00:00+00:00"
    >>> import datetime
    >>> datetime.datetime.strptime(d, '%Y-%m-%d').date()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
    data_string[found.end():])
    ValueError: unconverted data remains:  00:00:00+00:00
    


Answer: The error is pretty explicit in stating that you have an uncovered portion of
your string that wasn't expected based on what you are trying to convert.

You have provided this:

    
    
    d = "1997-01-29 00:00:00+00:00"
    

You are trying to convert based on this pattern:

    
    
    '%Y-%m-%d'
    

The error is stating:

    
    
    ValueError: unconverted data remains:  00:00:00+00:00
    

So, you should simply strip off that time portion based on how you are
converting. I simply changed your string to this and it worked:

    
    
    >>> d= "1997-01-29"
    >>> datetime.datetime.strptime(d, '%Y-%m-%d').date()
    datetime.date(1997, 1, 29)
    

