Re: finding out the age from a birthdate

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

 



On Tue, 14 Dec 2004 22:37:41 +0100, Merlin <news.groups@xxxxxx> wrote:
> i am somehow strugling to find out how to get the age of a person from its
> birthdate.
> 
> Has anybody an idea how to do that?

function getAge( $b )
{
    $b = date( 'Y-m-d', strtotime( $b ) );
    $a = explode( '-', $b );
    $age = date( 'Y-m-d' ) - $b;
    return ( date( 'nd' ) < $a[ 1 ].str_pad( $a[ 2 ], 2, '0', STR_PAD_LEFT ) )
        ? $age -= 1
        : $age;
}

echo getAge( $birthday );


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
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