Difference between two dates in php

For calculating difference between two dates in php we are make two functions, getDiff and its helping function daysInMonth,getDiff returns difference in array and daysInMonth returns days in month of given year and they are as follow:


<?php
$date1="03-Jul-1976";
$date2="05-Jun-2013";
$diff=getDiff($date1,$date2);

print_r($diff);

function getDiff($date1,$date2){
$dt1=strtotime($date1);
$dt2=strtotime($date2);
$y1=date('Y',$dt1);
$m1=date('m',$dt1);
$d1=date('d',$dt1);

$y2=date('Y',$dt2);
$m2=date('m',$dt2);
$d2=date('d',$dt2);
$days=0;$months=0;$years=0;
if($d2<$d1)
{ 
$d2=$d2+daysInMonth($m2,$y2);
$m2=$m2-1;
}
if($m2<$m1)
{
$m2=$m2+12;
$y2=$y2-1;
}
//////////////Final Result////////////////
$d=$d2-$d1;
$m=$m2-$m1;
$y=$y2-$y1;
$result=array("d"=>$d,"m"=>$m,"y"=>$y);
return $result;
}
function daysInMonth($m,$y)
{	$month=(int)$m;
$year=(int)$y;
switch($month):
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;
case 4:
case 6:
case 9:
case 11:
return 30;
break;
case 2:
if(($year%4==0) || ($year%100==0) || ($year%400==0))
return 29;
else
return 28;
break;
default:
return 0;
break;
endswitch;

}