
<?php
	function datediff($date_start, $date_end)
	{
		$diff = $date_end - $date_start;
	    list($tm, $td, $ty) = split("[-/]", $date_end);
	    list($bm, $bd, $by) = split("[-/]", $date_start);
	    
	    $ydiff = $ty - $by;
	    $mdiff = $tm - $bm;
	    $ddiff = $td - $bd;
	    
	    $months = ($ydiff * 12) + $mdiff;

		if ($ddiff < 0)
		{
			$months--;
			$calcmonth = $tm - 1;
			if ($calcmonth == 0) $calcmonth = 12;
			$numdays = cal_days_in_month(CAL_GREGORIAN, $calcmonth, $ty);
			$ddiff = $numdays - $bd + $td;
		}

		$weeks = floor($ddiff / 7);
		$days = $ddiff % 7;

		$r = array($months, $weeks, $days);
		return $r;

	}
		
	function kids_age($kids_name, $date_start)
	{
		$date_end = date("m-d-Y");  // Today's date
		//$date_start = "3-21-2005";  // Albert's birthday
		list($kids_age_m, $kids_age_w, $kids_age_d) = datediff($date_start, $date_end);	
	
		$kids_text_d = "";
		$kids_text_w = "";
		$kids_text_m = $kids_name." is $kids_age_m months";
	
		if (($kids_age_w + $kids_age_d) == 0)
		{
			$kids_text_m = $kids_name." is exactly $kids_age_m months";
		}
		else
		{
			if ($kids_age_d > 0)
			{
				$kids_text_d = ", and $kids_age_d day";
				if ($kids_age_d > 1) $kids_text_d = $kids_text_d."s";
	
				if ($kids_age_w > 0) $kids_text_w = ", $kids_age_w weeks";
			}
			else
			{
				$kids_text_w = " and $kids_age_w week";
				if ($kids_age_w > 1) $kids_text_w = $kids_text_w."s";
			}
		}
	
		$t = $kids_text_m.$kids_text_w.$kids_text_d." old.";
		return $t;
	}	
?>

