later列为datetime,某些字段的值为2017-05-01 04:07:00
我想更改当前日期和时间大于later值的行中的某些字段。

目的是发布已设置为稍后发布的帖子。

$current = date('Y-m-d H:i:s');

$sql = "update posts set status = :astatus, user = :auser, pass = :apass where later < :alater";
$stmt = $db->prepare($sql);
$stmt->execute(array(
    ":astatus" => 'public',
    ":auser" => '',
    ":apass" => '',
    ":alater" => $current
));


一切都没有改变。

最佳答案

不要使用时间,而是使用数据库时间:

$sql = "update posts set status = :astatus, user = :auser, pass = :apass where later < now()";
$stmt = $db->prepare($sql);
$stmt->execute(array(
    ":astatus" => 'public',
    ":auser" => '',
    ":apass" => ''
));

10-07 17:56