fork download
  1. <?php
  2.  
  3.  
  4. $data1 = new DateTime('19910906');
  5. $data2 = new DAteTime('19981205');
  6.  
  7. $idade = $data1->diff($data2);
  8.  
  9. echo "Idade: " . $idade->y . " anos.<br>";
  10.  
  11. var_dump($idade);
Success #stdin #stdout 0.03s 52472KB
stdin
Standard input is empty
stdout
Idade: 7 anos.<br>object(DateInterval)#3 (15) {
  ["y"]=>
  int(7)
  ["m"]=>
  int(2)
  ["d"]=>
  int(29)
  ["h"]=>
  int(0)
  ["i"]=>
  int(0)
  ["s"]=>
  int(0)
  ["weekday"]=>
  int(0)
  ["weekday_behavior"]=>
  int(0)
  ["first_last_day_of"]=>
  int(0)
  ["invert"]=>
  int(0)
  ["days"]=>
  int(2647)
  ["special_type"]=>
  int(0)
  ["special_amount"]=>
  int(0)
  ["have_weekday_relative"]=>
  int(0)
  ["have_special_relative"]=>
  int(0)
}