Posted By

dsoms on 03/17/11


Tagged

php difference dates


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

skywalker
uberdragon
scilec


Calculate the difference between two dates (PHP 5 >= 5.3.0)


 / Published in: PHP
 

  1. $date1 = new DateTime("2008-03-15");
  2. $date2 = new DateTime("2011-03-16");
  3.  
  4. $interval = $date1->diff($date2);
  5.  
  6. echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";

Report this snippet  

You need to login to post a comment.