我编写了一个python脚本来将数据从excel电子表格导入mysql数据库。但excel电子表格中有两列采用以下自定义格式:YYYY-MM-DD HH:MM:SS。mysql表中有datetime格式的列。但是,当我运行脚本时,我得到了一个错误:在SQL中不能将此格式添加到datetime格式中。在
下面是我的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()
有谁能告诉我如何在mySQL的datetime字段中插入excel中的日期时间列??在