
<?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($m, $w, $d) = datediff($date_start, $date_end);	

		$kids_text_d = "";
		$kids_text_w = "";
		$kids_text_m = $kids_name." is $m months";

		
		if ($d > 0)
		{
			$s = "";
			if ($d > 1) $s = "s";
			$t = $d . " day" . $s;
			if ($w > 0)  // some days, some weeks
			{
				$s = "";
				if ($w > 1) $s = "s";
				$t = $w . " week" . $s . ", and " . $t;
				if ($m > 0)  // some days, some weeks, some months
				{
					$s = "";
					if ($m > 1) $s = "s";
					$t = $m . " month" . $s . ", " . $t;
				}
				else  // some days, some weeks, zero months
				{
					//
				}
			}
			else  // some days, zero weeks
			{
				if ($m > 0)  // some days, zero weeks, some months
				{
					$s = "";
					if ($m > 1) $s = "s";
					$t = $m . " month" . $s . ", and " . $t;
				}
				else  // some days, zero weeks, zero months
				{
					//
				}
			}
		}
		else  // zero days
		{
			if ($w > 0)  // zero days, some weeks
			{
				$s = "";
				if ($w > 1) $s = "s";
				$t = $w . " week" . $s;
				if ($m > 0)  // zero days, some weeks, some months
				{
					$s = "";
					if ($m > 1) $s = "s";
					$t = $m . " month" . $s . ", and " . $t;
				}
				else  // zero days, some weeks, zero months
				{
					//
				}
			}			
			else  // zero days, zero weeks, must be some months!
			{
				$s = "";
				if ($m > 1) $s = "s";
				$t = $m . " month" . $s;
			}
			$t = "exactly " . $t;

		}
		
		$t = $kids_name . " is " . $t . " old";

		return $t;
	}	
?>

