python - How to insert a date time column from excel into datetime field in mySQL? -
i have written python script import data excel spreadsheet mysql database. 2 of columns in excel spreadsheet in following custom format: yyyy-mm-dd hh:mm:ss
. , mysql table has these columns in datetime
format. when run script error format cannot added datetime format in sql.
below python script:
query = """insert table (col1, col2, col3, col4, col5) values (%s, %s, %s, %s, %s)""" r in range(1, sheet.nrows): col1 = sheet.cell(r,0).value col2 = sheet.cell(r,1).value col3 = sheet.cell(r,2).value col4 = sheet.cell(r,3).value col5 = sheet.cell(r,4).value #col5 = xlrd.xldate.xldate_as_datetime(sheet.cell(r,4).value, book.datemode) # assign values each row values = (col1, col2, col3, col4, col5) # execute sql query cursor.execute(query, values) # close cursor cursor.close() # commit transaction con.commit()
can tell me how insert date time column excel datetime field in mysql??
Comments
Post a Comment