PHP – Calculate the Difference Between Two Dates (PHP 5 >= 5.3.0)

Code Example:
<?php
$date1 = new DateTime("2010-04-15");
$date2 = new DateTime("2011-05-16");

$interval = $date1->diff($date2);

echo "Difference: " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *