Zend - The PHP Company




Calculators

Add Code


Date of Birth time to Age conversion  

Type: code fragment
Added by: nogray
Entered: 15/04/2006
Last modified: 04/12/2005
Rating: - (fewer than 3 votes)
Views: 4613
This function will take the date of birth in a time format (from mktime() function) and convert it into age in years, months, and days.


<?php
function get_Age($DOB){
    
$dayinseconds 24 60 60;
    
$dayinYear 0.00273972602739726;
    
    
$dif time() - $DOB;
    
    
$age_in_days $dif/$dayinseconds;
    
    
$flt_year $age_in_days $dayinYear;
    
$yearfloor($flt_year);
    
    
$flt_month = ($flt_year $year) * 12;
    
$month floor($flt_month);
    
    
$flt_day = ($flt_month $month) * 30.58;
    
$day floor($flt_day);
    
    return 
"$year yrs, $month mnths and $day days";

?>


Usage Example




Rate This Script





Search



This Category All Categories