r0xette r0xette - 1 year ago 103
Python Question

Convert date format to insert into mysql db

I have pandas column

which contains date in format
. I am trying to insert it into mysql db but having problems due to incorrect format of date field data. It has to be converted into
in order to be inserted. Without storing the new value in variable how can I convert the date into required format?

Current format: 11/05/2015
Required format: 2015-11-05

Mat Mat
Answer Source

Is the current format mm/dd/yyyy? If so

from datetime import datetime
row['date'] = datetime.strptime(row['date'], '%m/%d/%Y').strftime('%Y-%m-%d')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download