Pages

how to get difference between two dates in php

Wednesday, 19 March 2014


how to get difference between two dates in php

<?php
$date1 = new DateTime("2006-09-07");
$date2 = new DateTime("2014-03-19");
$interval = $date1->diff($date2);
echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
?>

Output: difference 7 years, 6 months, 12 days
 

Most Reading