fork(1) download
  1. <?php
  2.  
  3. $dob = new DateTime('24 June 1940');
  4. $now = new DateTime('23 June 2012');
  5. echo year_diff($now, $dob)."\n";
  6. $now = new DateTime('24 June 2012');
  7. echo year_diff($now, $dob)."\n";
  8.  
  9. function year_diff($date1, $date2) {
  10. list($year1, $dayOfYear1) = explode(' ', $date1->format('Y z'));
  11. list($year2, $dayOfYear2) = explode(' ', $date2->format('Y z'));
  12. return $year1 - $year2 - ($dayOfYear1 < $dayOfYear2);
  13. }
  14.  
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
71
72