PHP SQL删除日期<当前的日期?

时间:2014-07-11 15:41:41

标签: php sql magento date datetime

我的数据库中有一个名为expire_datetime_off的表。它的格式是2014-07-11 00:00:00,如果此日期在当前日期之前,我想删除该行。我在Magento PHP中有一个当前日期的变量。我无法弄明白。任何帮助表示赞赏

public function onclearAction()
{
    $mysqli=mysqli_connect("IP","NAME","PASSWORD","SCHEMA");
    if ($mysqli->connect_errno) {
        return $mysqli->connect_error;
    }
    $currenttime = strtotime(Mage::getModel('core/date')->date('Y-m-d H:i:s'));
    mysqli_query($mysqli,"DELETE FROM belvg_countdown WHERE expire_datetime_off < convert(datetime, '$current_time')");
}

2 个答案:

答案 0 :(得分:1)

您可以使用数据库当前时间:

DELETE FROM belvg_countdown
    WHERE expire_datetime_off < now();

答案 1 :(得分:0)

It's format is 2014-07-11 00:00:00

如果它采用这种格式,则无需将其转换为比较

$currenttime = Mage::getModel('core/date')->date('Y-m-d H:i:s');
mysqli_query($mysqli,"DELETE FROM belvg_countdown WHERE expire_datetime_off <  '$current_time'");