note 24670 deleted from function.date by philip

From: Date: Sat, 26 Oct 2002 22:34:40 +0000
Subject: note 24670 deleted from function.date by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-38606@lists.php.net to get a copy of this message
Here is a simple plain english function script which will find a persons age given birthdate. <?php function calc_age($month,$day,$year) { // get current date broken down into month,day,year variables. $month_now=date("m"); $day_now=date("d"); $year_now=date("Y"); // initial guess at age is differance between this year and birth year. $age=$year_now-$year; // if birth month is same as current month, then must look at date to get age if ($month_now == $month) { // if the birthday has not come yet then age is age-1 if ($day_now < $day) { return ($age-1); } else { //if the birthday has already come then age is acurate return ($age); } } //if birth month has not come yet, then age is age-1 elseif ($month_now < $month) { return ($age -1); } else { //if birth month has already come then age is acurate return ($age); } } ?>

« previous php.notes (#38606) next »