我需要Excel中的数据-这样的int类型的date(20180301)和time(121220)。我想将excel导入mysql,使用python将datetamp(%t-%m-%d%H:%M:%S)转换为一个库仑。
import xlrd
import pymysql
import time
import datetime
#open the workbook and define rhe worksheet
book = xlrd.open_workbook("d:/waiting2.xlsx")
sheet = book.sheet_by_index(0)
ts = time.time()
timestamp = datetime.datetime.formtimestamp(ts).strftime('%t-%m-%d %H:%M:%S')
#sheet = book.sheet_by_index(0)
#establish a mysql connection
database = pymysql.connect(host="localhost", user='root', password='1234',db='test')
#get the cursor, which is used to traverse the database, line by line
cursor = database.cursor()
try:
cursor.execute("""INSERT into test(date+time) values($s)""", (timestamp))
database.commit()
except:
database.rollback()
database.close()
AttributeError:类型对象“ datetime.datetime”没有属性“ formtimestamp”
相关分类