note 24670 added to function.date
| From: | mhowatt at comstarguard dot com | Date: | Sun, 25 Aug 2002 04:38:05 +0000 |
| Subject: | note 24670 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35566@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);
}
}
?>
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+24670
http://master.php.net/manage/user-notes.php?action=delete+24670
http://master.php.net/manage/user-notes.php?action=reject+24670