I am getting an error while trying to parse a string to date.
ValueError: unknown string format
Here is my code
dateString = "02/11/2016"
print dateString
dt = parse(dateString)
item.date = calendar.timegm(dt.utctimetuple())
print dt
The funny part is, it is printing the correct date before throwing the error. Here is the complete log
02/11/2016 2016-02-11 00:00:00 art. 10, comma 1, lettera e Traceback (most recent call last): File "institutional-docs.py", line 60, in dt = parse(dateString) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.py", line 697, in parse return DEFAULTPARSER.parse(timestr, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.py", line 303, in parse raise ValueError, "unknown string format" ValueError: unknown string format
What's wrong with using time?
your question doesn't specify what your parse
function does so can't say if that's reading the string in any weird way. Chances are you've copied and pasted bad quotation marks.
import time
time.strptime("02/11/2016", "%d/%m/%Y")