It is necessary to compare the current time with the set one, if the current time is more than the set one by at least 30 minutes, then output the phrase. I get this error Call to a member function format () on boolean. Tell me where I'm wrong

$datetime1 = new DateTime(); $datetime2 = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()); // выводит дату в формате сайта 08.09.2017 10:17:57 $interval = $datetime1->diff($datetime2); $m = $interval->format('%i'); $h = $interval->format('%h'); if($m > 30 || $h > 1){ echo "time"; } 
  • and before that, most likely I should write the error type 2 -- DateTime::diff() expects parameter 1 to be DateTimeInterface, string given because you give the parameter a string, but you need DateTime - Alexey Shimansky
  • First, check what CMS functions return to you - DaemonHK
  • here it is not necessary to change the question in the course of the play - Alexey Shimansky
  • forgive the mistake I noticed, so I changed the code - ChromeChrome
  • Why bother? Two time stamps checked and that's it. 30 minutes = 1800 seconds. - Visman

2 answers 2

Replace

 $datetime2 = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()); 

on

 $datetime2 = new DateTime($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()); 

    The problem is most likely that $datetime2 is passed as a string, but also as a DateTime

     $datetime2 = new DateTime(date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time())); ^^^^^^^^^^^^^