我使用python将日期插入MySQL。在插入日期之前,我将日期格式更改为:
start_datetime_object = datetime.datetime.strptime(str(stDate), '%Y-%m-%d')
end_datetime_object = datetime.datetime.strptime(str(enDate), '%Y-%m-%d')
d_stDate= start_datetime_object.strftime('%Y-%m-%d')
d_enDate= end_datetime_object.strftime('%Y-%m-%d')
当我使用logging.debug("DATES---->" + d_enDate +'-- '+ d_stDate)
时
我得到的结果应为%Y-%m-%d
格式。
此刻,我坚持使用datetime.date(2018, 6, 30)
编辑:
我的查询是:
cursor1.execute("INSERT INTO "+MYSQL_DB+".events ( `name`, `type`, `startDate`,`endDate`, `location` ) VALUES (%s,%s,%s,%s,%s)",[ str(name), str(types), str(d_stDate),str(d_enDate),str(location)])