D. Henry D. Henry - 9 days ago 4
MySQL Question

Why is My MYSQLI DELETE set on interval function not running

I have search and tried all codes I could find to try to delete certain rows based on an 8hr interval from current time but it is not working. I put it in the header and in other pages. here is my code:

`date_default_timezone_set('Country/City');
if (isset($_SESSION["login"])) {
$display = $_SESSION["login"];
$day_nudge = mysqli_query($conn,"DELETE FROM nudges WHERE nudge_time < DATE_ADD(NOW(), INTERVAL -8 HOUR)");
}`


I have also tried other ways such as:

DELETE FROM nudges
WHERE nudge_time < (NOW() - INTERVAL 8 HOUR)

DELETE FROM nudges
WHERE nudge_time < DATE_SUB(NOW(), INTERVAL 8 HOUR)


these all worked on local host but now its on my server it does not execute.

Answer

After taking a break and playing with some other bugs... I came back and just thought I would try something and it worked for me, thought I would post it here incase anyone else may find it useful.

$datnudge = date('Y-m-d H:i:s', strtotime('-8 hour'));
$day_nudge = mysqli_query($conn,"DELETE FROM nudges WHERE nudge_time <= '$datnudge'");