|
Posted by Mark Cain on 05/04/05 14:53
The following code was taken directly from
www.php.net/date
<?php
function CalcAge($date_of_birth) { // YYYY-MM-DD
$cur_year=date("Y");
$cur_month=date("m");
$cur_day=date("d");
$dob_year=substr($date_of_birth, 0, 4);
$dob_month=substr($date_of_birth, 5, 2);
$dob_day=substr($date_of_birth, 8, 2);
if($cur_month>$dob_month || ($dob_month==$cur_month &&
$cur_day>=$dob_day) )
return $cur_year-$dob_year;
else
return $cur_year-$dob_year-1;
}
?>
Mark Cain`
----- Original Message -----
From: "Ryan A" <ryan@coinpass.com>
To: "php" <php-general@lists.php.net>
Sent: Tuesday, May 03, 2005 3:41 PM
Subject: [PHP] age function
> Hey,
> Anybody have an age function where i can pass a date object and get back
an
> int?
>
> eg:
> $years_old=get_years("1979-12-07");
>
> Thanks,
> Ryan
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.11.2 - Release Date: 5/2/2005
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
[Back to original message]
|