python / django strptime "bad directive" -


i'm trying convert string date object, have line of code:

datetime.strptime('01/04/2014', '%d/%m%/%y') 

and get:

valueerror: '/' bad directive in format '%d/%m%/%y' 

i have tried changing / other characters , no separator throws same error (for character)

django 1.5.1 python 2.7.3

any idea means? google doesn't throw many results same problem.

you have 1 % many after %m directive; %/ not valid directive , valueerror tells that.

use:

datetime.strptime('01/04/2014', '%d/%m/%y') 

instead, using %y (capital y) parse year century.

demo:

>>> datetime.strptime('01/04/2014', '%d/%m/%y') datetime.datetime(2014, 4, 1, 0, 0) 

Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -