I tried this and works fine for me
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-10');
$difference = $datetime1->diff($datetime2);
echo formatOutput($difference);
function formatOutput($diff){
/* function to return the highrst defference fount */
if(!is_object($diff)){
return;
}
if($diff->y > 0){
return $diff->y .(" year".($diff->y > 1?"s":"")." ago");
}
if($diff->m > 0){
return $diff->m .(" month".($diff->m > 1?"s":"")." ago");
}
if($diff->d > 0){
return $diff->d .(" day".($diff->d > 1?"s":"")." ago");
}
if($diff->h > 0){
return $diff->h .(" hour".($diff->h > 1?"s":"")." ago");
}
if($diff->i > 0){
return $diff->i .(" minute".($diff->i > 1?"s":"")." ago");
}
if($diff->s > 0){
return $diff->s .(" second".($diff->s > 1?"s":"")." ago");
}
}
Check this link for reference here
Thanks! and have fun.