Subtract variables Datetime [duplicate]

1

I have two datetime fields and I would like to know the difference between them. I'm developing in Php Gtk, so the functions have to be of the lowest possible level.

    
asked by anonymous 25.07.2016 / 20:50

1 answer

0

One of the ways to do this object-oriented, is to use the DateTime class, it has the diff method that returns a DateInterval object, which represents the interval between two distinct dates:

Following the example dates:

  $data1 = new DateTime( '2013-12-11' );
  $data2 = new DateTime( '1994-04-17' );

  $intervalo = $data1->diff( $data2 );

  echo "Intervalo é de {$intervalo->y} anos, {$intervalo->m} meses e {$intervalo->d} dias"; 

Source: How to calculate the difference between two dates ?

    
25.07.2016 / 22:07