Getting time difference in python 2.7
Question: I am importing some data from a REST API into a list. One of the columns
contains just date/time information.

Column A format/example : `2015-06-11 07:59:10.000 GMT`

I need to be able to check the time difference between two rows , i tried
using

    
    
    datetime.strptime(variable_name, "%Y-%m-%d %H:%M:%S")
    

however i got the following error :

    
    
    ValueError: unconverted data remains: .000 GMT
    

Is there any way to fix this without having to modify and remove the offending
part out of every entry in my list ?

Any help would be greatly appreciated.


Answer: You need to use `%f` for decimal part and `%Z` for timezone :

    
    
    >>> variable_name='2015-06-11 07:59:10.000 GMT'
    >>> datetime.strptime(variable_name, "%Y-%m-%d %H:%M:%S.%f %Z")
    datetime.datetime(2015, 6, 11, 7, 59, 10)
    

