How to select row which has 3 hours ago

时间:2016-05-17 11:11:18

标签: php datetime select mysqli

i have table which has column completed_at type (datetime)

i am inserting date in it by php date('Y-m-d H:i:s') 2016-05-17 00:00:14

I want to select data which has 3 hours ago

<?php
$sql = "Select `id`,`file` from `uploader` where `completed_at` < CURDATE() - INTERVAL 3 HOUR";
        $DB = new DB();

        mysqli_query($DB->db_connect(), $sql);

?>

but it gives me wrong answer.

1 个答案:

答案 0 :(得分:2)

Try this:

SELECT FROM table_name
 WHERE completed_at  < NOW() - INTERVAL 3 HOUR