我想实现日期增加天数,从错误来看日期已经增加了,但是为什么还会出现数据转换错误的问题
功能实现代码
def update(self):
datestr = self.timeInput.text()
date_time_obj = datetime.strptime(datestr, '%Y-%m-%d')
new_date = (date_time_obj + timedelta(days=7)).strftime('%Y-%m-%d')
borrow2 = Rbook.my_construtor2(None, None, None, new_date)
if borrowDao.add(borrow2) > 0:
self.x = show_custom_message_box("系统提示", "借阅成功!")
self.resetForm()
self.initTable()
else:
self.x = show_custom_message_box("系统提示", "借阅失败!")
数据库模块代码
def update(rbook: Rbook) -> int:
"""
更新数据
:param rbook:
:return:
"""
con = None
try:
con = dbUtil.getCon()
cursor = con.cursor()
# 更新数据
sql = f"UPDATE borrow SET returnDate = DATEADD(week, 1, '{rbook.returnDate}') WHERE bid = '{rbook.bid}'"
cursor.execute(sql)
con.commit()
return cursor.rowcount
except Exception as e:
print(f"更新数据时发生错误: {e}")
if con is not None:
con.rollback()
return 0
finally:
dbUtil.closeCon(con)
Conversion failed when converting the varchar value '2024-05-03' to data type int