I have quite a situation here, I'm currently trying to code something which will give reminders of certain events, or tasks. For that, I have a ajax function, which will check every 10 minutes if there is a reminder to display. It's working fine until I try to compare the reminder's date and today's date.
I'm accessing my database to fetch all the events which have the flag for the reminder, and I get the duration needed for this reminder (ex : 15 minutes, 3 hours, 2 weeks) through an already written function which will get me the duration in minutes.
The main problem is, when I try to substract the duration to my current date (to have the reminder's date), nothing is happening, the $date_rappel, is the same a the $date_current. I searched everywhere to see if I'm doing it wrong, but I can't see the problem.
I tried to trigger_error() and var_dump() every single variable I have in my code to see if something was odd, but everything seems normal.
$events = '[';
$zz=0;
for ($r=0;$r < count($array_search_result);$r++)
{
$data=new $class_name;
$data->load($array_search_result[$r]);
$rappel = get_simple_obj('reminder_table',$data->cle_antlist_rappels);
$duree = $rappel['duree'];
$tmp_date = strval($data->date_echeance);
$tmp_heure = strval($data->heure_echeance);
$date_and_time = $tmp_date." ".$tmp_heure;
$date_current = new DateTime($date_and_time);
$date_rappel = $date_current;
if($duree < 60){
$tmpinterval = 'PT'.$duree.'M';
$interval = new DateInterval($tmpinterval);
$date_rappel->sub($interval);
}elseif($duree >= 60 && $duree < 1440){
$duree = $duree / 60;
$tmpinterval = 'PT'.$duree.'H';
$interval = new DateInterval($tmpinterval);
$date_rappel->sub($interval);
}elseif($duree >= 1440 && $duree < 10080){
$duree = $duree / 60 / 24;
$tmpinterval = 'P'.$duree.'D';
$interval = new DateInterval($tmpinterval);
$date_rappel->sub($interval);
}else{
$duree = $duree / 60 / 24 / 7;
$tmpinterval = 'P'.$duree.'W';
$interval = new DateInterval($tmpinterval);
$date_rappel->sub($interval);
}
if($date_current < $date_rappel == true){
// Add the event with the reminder to the ajax request
}
$events .= $event;
$events .= ']';
$returnSate = 'OK';
$status_response=0;
This is what the trigger_error of $date_current
and $date_rappel
are returning :
PHP Notice: 11:39:00 2019-05-14 in .../operation-reminder.php on line 308
PHP Notice: 11:39:00 2019-05-14 in .../operation-reminder.php on line 309