I was writting a car rental application for some customer, when i came across this problem. Fortunatelly I found the  solution easier that I thought. You have to love google!

So here is the solution: Takes into account leap years and it’s tested and it works great.



	function dateDiff($start, $end) 
		$start_ts = strtotime($start);
		$end_ts = strtotime($end);
		$diff = $end_ts - $start_ts;
		$start_array = explode("-", $start);
		$start_year = $start_array[0];
		$end_array = explode("-", $end);
		$end_year = $end_array[0];
		$years = $end_year-$start_year;
		if (($years%4) == 0) 
			$extra_days = ((($end_year-$start_year)/4)-1);
			$extra_days = ((($end_year-$start_year)/4));
		$extra_days = round($extra_days);
		return round($diff / 86400)+$extra_days+1;
echo dateDiff("2006-04-05", "2006-04-01");

The format of the dates is: yyyy-mm-dd