如何在excel中插入date时间列到MySQL中的date时间字段?

我已经写了一个Python脚本来从Excel电子表格导入数据到MySQL数据库。 但是,Excel电子表格中的两列是以下自定义格式: YYYY-MM-DD HH:MM:SS 。 而MySQL表格有这些datetime格式的列。 但是,当我运行脚本我得到错误,这种格式不能被添加到SQL中的date时间格式。

下面是我的Python脚本:

 query = """INSERT INTO table (col1, col2, col3, col4, col5) VALUES (%s, %s, %s, %s, %s)""" for 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 from each row values = (col1, col2, col3, col4, col5) # Execute sql Query cursor.execute(query, values) # Close the cursor cursor.close() # Commit the transaction con.commit() 

任何人都可以告诉我如何插入从Excel的date时间列到MySQL中的date时间字段?