Why function for time difference in PHP incorrectly fulfills. At the moment, 15:25 02/15/2018, but for the time of 2018-02-16 16:00:00 it gives the difference in: $ diff: 2160. Why can this be?
foreach ($response['orders'] as $order) { $order['customFields']['time_perezvona'] = str_replace('tp', '', $order['customFields']['time_perezvona']); if (strlen($order['customFields']['time_perezvona']) < 4) { $order['customFields']['time_perezvona'] = substr_replace($order['customFields']['time_perezvona'], ':', 1, 0); } else { $order['customFields']['time_perezvona'] = substr_replace($order['customFields']['time_perezvona'], ':', 2, 0); } $order['customFields']['time_perezvona'] .= ':00'; $time_sled_shaga = $order['customFields']['data_sled_shaga'] . ' ' . $order['customFields']['time_perezvona']; echo $time_sled_shaga . '<br>'; $datetime1 = new DateTime($time_sled_shaga); $datetime2 = new DateTime('now'); $interval = $datetime1->diff($datetime2); $diff = $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s'); echo '$diff: ' . $diff . '<br>'; if ($diff < 7200) { $infoForEdit = array( 'id' => $order['id'], 'status' => 'srochno' ); // $response2 = $retail->request->ordersEdit($infoForEdit, 'id', $order['site']); // echo "<pre>" . print_r($response2); } } In the loop, I output $ diff and here is an example of two values:
2018-02-16 9:00
$ diff: 62995
2018-02-16 16:00
$ diff: 1795
if ($datetime1 < new datetime('-2 hour'))if I correctly understood what you want to do. - Fine