Date Difference issue in Python 2.7.8

Peter Otten __peter__ at web.de
Fri Feb 20 06:18:56 EST 2015


Puruganti Ramesh wrote:

> I have an issue in comparing dates in python 2.7.8

No, you are stuck with parsing the dates, you don't get to the point of 
comparing them.

> I am getting below excption
> Traceback (most recent call last):
> File "FunctionUpdate.py", line 204, in <module>
> dt_dateb = datetime.strptime(dt_strq, '%Y-%m-%d').date()
> File "/usr/local/lib/python2.7/_strptime.py", line 328, in _strptime
> data_string[found.end():])
> ValueError: unconverted data remains:
> 

Look closely at the line above. You don't see anything? 
Well, that's a newline, I suspect ;) 

If you are reading dates from a file dt_strq is probably "2014-9-11\n"  
instead of the "2014-9-11" you and the strptime() method expect. Try 
removing any whitespace with 

dt_strq = dt_strq.strip()

before passing it to datetime.strptime()




More information about the Python-list mailing list