I’m converting a string into time object in python 2.4.
d1 = time.strptime(d2, '%Y-%m-%d %H:%M:%S.%%')
Here d2 is '2012-11-07 13:41:13.138807'
I’m getting the following error.
ValueError: time data did not match format: data=2012-11-07 13:41:13.138807 fmt=%Y-%m-%d %H:%M:%S.%%
Any solution?
Try adding
.%fto your string (Python 2.6+), which should handle the value (although it does not appear to be stored):The solution from @bradleyayers will accurately capture your microsecond value if needed, so if you need that, I would suggest using his way 🙂
Since the
%fparameter fordatetime/timeisn’t available pre-2.6, and if you don’t need to capture the microseconds, you can try something like this (rough idea that splits on the period and takes the first element – could likely be optimized):