public function my_function(){ $today = new DateTime(); // if you want the current day (i.e. today) you don't need any arguments when instantiating a DateTime $today = $today->format('Y-m-d'); // will give a string in the format e.g. '2022-01-22' $mailtest = '[email protected]'; $sql = "SELECT " . _DB_PREFIX_ . "module.id, " . _DB_PREFIX_ . "module.mail, " . _DB_PREFIX_ . "module.alert, " . _DB_PREFIX_ . "module.commentaire, " . _DB_PREFIX_ . "module.datetime, " . _DB_PREFIX_ . "module.statut FROM `" . _DB_PREFIX_ . "module` WHERE id=" . (int)Tools::getValue('id_com'); $com = Db::getInstance()->ExecuteS($sql); foreach ($com as $row){ if(substr($row['alert'],0,10) == $today) { //compare the first 10 characters of the DB value (e.g. '2022-01-22') to the formatted DateTime. $alert = $row['alert']; $email = $row['mail']; $coment = $row['commentaire']; $date =$row['datetime']; $this->sendEmailAlert($alert,$email,$coment,$date); } } }
See changes and comments above for matching date formats, hope that helps.