fork download
  1. <?php
  2.  
  3. $d1 = DateTime::createFromFormat('Y-m-d', '2014-03-11');
  4. $d2 = DateTime::createFromFormat('Y-m-d', '2014-04-01');
  5.  
  6. printf("Whole months difference: %d\n", $d2->diff($d1)->format('n'));
  7. printf("Indexes difference: %d\n", $d2->format('n') - $d1->format('n'));
  8.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Whole months difference: 0
Indexes  difference: 1