r0xette r0xette - 4 months ago 41
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

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')