Re: age function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
To: "php" <php-general@xxxxxxxxxxxxx>
Sent: Tuesday, May 03, 2005 3:41 PM
Subject:  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
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux