On 02/20/2015 04:28 AM, Puruganti Ramesh wrote:
Hi Friends,

I have an issue in comparing dates in python 2.7.8
I have written code as below but i am getting error
Code is :
import datetime as dt
from datetime import datetime
from datetime import datetime, timedelta, date

dt_str='2014-5-11'
dt_strq='2014-9-11'

dt_datea = datetime.strptime(dt_str, '%Y-%m-%d').date()
dt_dateb = datetime.strptime(dt_strq, '%Y-%m-%d').date()
dt_diff = dt_dateb - dt_datea
print dt_diff.days

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:


I think it's great that you reduced a 200+ line program into a 9 line simple case. that's always a good idea, and frequently it helps you solve your own problem, reducing it for public comment.

But the other requirement is that you actually test that the code you show produces the error you show. It does not, probably because those strings in the literals are not exactly what you had in the original.


--
DaveA
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to