zinon zinon - 1 year ago 122
Python Question

Django date format issue using strptime().date

I'm using django 1.8 in python 2.7

My code is

(datetime.strptime('diagnosis_circumstances_date', "%Y-%m-%d")).date()

and us a result I get
time data 'diagnosis_circumstances_date' does not match format '%Y-%m-%d'

My date is

Answer Source

You should use the variable diagnosis_circumstances_date, not the string 'diagnosis_circumstances_date'.

datetime.strptime(diagnosis_circumstances_date, "%Y-%m-%d")).date()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download