Zend - The PHP Company




Calculators

Add Code


get_age()  

Type: code fragment
Added by: russlndr
Entered: 08/10/2001
Last modified: 02/12/2001
Rating: - (fewer than 3 votes)
Views: 5844
Calculates number of years since input date.


<?php
function get_age($date_of_birth) {
    list (
$year$month$day) = explode('-'$date_of_birth);
    
$age date('Y') - $year;
    if (
date('m') < $month$age--;
    elseif (
date('d') < $day$age--;
    return 
$age;
}
?>


Usage Example


$age = get_age('1981-03-29');


Rate This Script





Search



This Category All Categories