Personal tools
You are here: Home Software Scripts Excel-CSV to MySQL date transform Generation XML
Document Actions

Excel-CSV to MySQL date transform

MySQL expects dates to be of the format YYYY/MM/DD, while Excel exports to CSV as MM/DD/YYYY. Here's a python script to transform a (string) date field to a proper one.

for o in context.selectBlankDates():
  ID = o['ID']
  dateMonth = o['StringDate'][:2]
  dateYear = o['StringDate'][6:]
  dateDay = o['StringDate'][:5][3:]
  FixedDate = dateYear+'-'+dateMonth+'-'+ dateDay
  context.updateDate(ID=ID, FixedDate=FixedDate)
  print FixedDate

return printed