zinon zinon - 21 days ago 10
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
1980-08-28
.

Answer

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

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