如何在DATE字段中添加七天

时间:2015-11-19 15:49:50

标签: mysql

我想更新每个DATE字段并将其添加7天。我检查PHP中的DATE函数,但我没有找到适合MySQL语法的函数 我的疑问是:

$query_sched = "UPDATE events SET events.event_date = DATE(events.event_date + INTERVAL 7)";
$res = mysqli_query($dblink, $query_sched) or die (mysqli_error($dblink));

1 个答案:

答案 0 :(得分:1)

您错过了' +'

UPDATE events SET events.event_date = DATE(events.event_date + interval 7 day) WHERE events.event_id = '$event_id'



UPDATE events SET events.event_date = DATE_ADD(events.event_date , interval 7 day) WHERE events.event_id = '$event_id'

输出:

update test set test.date = date(test.date + interval 7 day) where test.id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0