设置cron并比较两个日期

时间:2015-08-12 11:49:38

标签: php mysql cron

我想在数据库中的日期前14小时发送邮件。我怎么能这样做?我应该如何在数据库中的日期之前14小时设置cron以及如何在代码中发送它?

在我的数据库中,我有cutoffs表(id,datetime,regio_id)。

在我的代码中我有例如:

    $dt = new DateTime();
    $trenutniDatumiVrijeme = $dt->format('Y-m-d H:m:s');

    $rez = mysqli_query($kon, "SELECT * FROM cutoffs");
    while($red = mysqli_fetch_assoc($rez)){
       $trDatum = strtotime($trenutniDatumiVrijeme);
       $cutOffDatum = strtotime($red["datetime"]);
       if(**it is 14hours to $cutOffDatum???**){
            *send mail*
       }
    }

我应该如何设置cron来运行此文件并仅发送此邮件一次?每小时,每5个小时,每14个小时或......?

我的查询是:

    //Uzimamo podatke za korisnika
            $rezKor = mysqli_query($kon, "SELECT * FROM korisnici WHERE id = ". $user_id ." LIMIT 1");
            $redKor = mysqli_fetch_assoc($rezKor);
            $korEmail = $redKor["email"];
            $naam = $redKor["ime"] . " " . $redKor["prezime"];
            $korPostcode = $redKor["postcode"];

            $trenutniDatum = strtotime($trenutniDatumiVrijeme);

    $rezCutoff = mysqli_query($kon, "SELECT cutoffs.id as cutoff_id, cutoffs.datetime as cutoffTime, regios.id as regioID, regios.naam as regioNaam, regio_deelgemeente_tt.id, deelgemeentes.regio_postcode FROM cutoffs 
INNER JOIN regios ON regios.id = cutoffs.regio_id 
INNER JOIN regio_deelgemeente_tt ON regios.id = regio_deelgemeente_tt.regio_id 
INNER JOIN deelgemeentes ON regio_deelgemeente_tt.deelgemeente_id = deelgemeentes.id 
WHERE deelgemeentes.regio_postcode = ". $korPostcode ." AND cutoffs.datetime > ". $trenutniDatum ." 
GROUP BY cutoffs.regio_id ORDER BY cutoffs.id DESC");

我有桌子截止 enter image description here

id 7的截止时间已经过去,但我仍然在我的结果中得到它。

0 个答案:

没有答案