我的 MySQL 表中有一个日期和状态列。当前帖子状态为 = 已发送/已接收。我只想更改状态 = 15 天后自动中止。
查询:
if (txtrecdate.Text == "" && ddlstatus.SelectedItem.Text != "Completed")
{
queryStr = "update barter_proposals set website_a=?web_a,email_id=?email,email_id2=?email2,email_id3=?email3,contact_name=?cname,proposal_status=?status,reason=?rsn," +
"comment1=?com1 ,agreement=?agreement,agrmt_filename=?agrmt_filename,comment2=?com2,comment3=?com3,lifespan_date=?lpdate where pro_id=?pro_id";
}
我用谷歌搜索并找到了这个解决方案:
UPDATE table SET status = "Aborted" where date=DATE_ADD(date, INTERVAL 15 DAY)
如何在我的更新查询中应用它?有没有其他方法可以在 15 天后自动更改状态?
最佳答案
查看 MySQL 事件。首先,您需要在 MySQL 端打开事件调度程序
https://dev.mysql.com/doc/refman/5.7/en/events-configuration.html
然后创建事件
delimiter $$
CREATE EVENT update_table_statuses
ON SCHEDULE
EVERY 1 DAY STARTS '2018-03-22 23:00:00'
DO
BEGIN
UPDATE table SET status = "Aborted" where date=DATE_ADD(date, INTERVAL 15 DAY);
END $$
delimiter ;
事件每天执行一次
关于c# - 如何在15天后自动更新状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49421184/