<?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);	
		
		$y = 0;
		if ($m > 23)
		{
			$y = floor($m / 12);
			$m = $m % 12;
		}

		if (($y + $m + $w + $d) == 0)  // if the kid is zero days old return right here!
		{
			$t = $kids_name . " was born today!";
			return $t;
		}
		
		$text_d = $text_d.$d." day";
		$text_w = $text_w.$w." week";
		$text_m = $text_m.$m." month";
		$text_y = $text_y.$y." year";

		// add plural
		if ($d > 1) $text_d = $text_d."s";
		if ($w > 1) $text_w = $text_w."s";
		if ($m > 1) $text_m = $text_m."s";
		if ($y > 1) $text_y = $text_y."s";
		
		$darry = array($y, $m, $w, $d);
		$tarry = array($text_y, $text_m, $text_w, $text_d);
		$datelist = array();
		
		for ($i = 0; $i <= 3; $i++)
		{
			if ($darry[$i] > 0) $datelist[] = $tarry[$i];
		}

		$t = "";
		$count = count($datelist);
		$t = $datelist[0];
		if ($count > 1) 
		{
			$t = "";
			for ($i = 0; $i < ($count - 1); $i++)
			{
				$t = $t.$datelist[$i].", ";
			}
			$t = $t."and ".$datelist[$count-1];
		}
		if ($d == 0) $t = "exactly ".$t;
			
		$t = $kids_name . " is " . $t . " old";

		return $t;
	}	

?>

