Warning: Cannot modify header information - headers already sent by (output started at /var/www/lalieno.it/index.php:48) in /var/www/lalieno.it/inc/cookie.php on line 3
a cadenza discontinua
Come se fossi
BLOG

PHP - Aggiungere o sottrarre intervalli ad un data ( datetime )

Un piccolo esempio di come sottrarre o aggiungere un intervallo, in questo caso un ora, ad un datetime.

$datevar = '2014-06-10 09:54:31';

      $date = new DateTime($datevar);

      // Set dell'intervallo
      $interval = new DateInterval('PT1H');

      // sottraggo
      $date->sub($interval);

      // aggiungo
      $date->sub($interval);

      echo (string)date_format($date, 'Y-m-d H:i:s');


di GuiZ
10/06/2014

Commenta

We'll never share your email with anyone else.