Results 1 to 2 of 2

Thread: Calculate Age

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Calculate Age

    I am trying to write a function that calculates the age of an individual exactly...not worried about month or days just years...every php function I have tried to use only calculates back to 1970...therefore anyone born before 1970 would show an age of 32. I need this function to be able to calculate the age of someone born back in the early 1880's and later...I have thought of just a basic calculation like this:
    PHP Code:
    function calculate_age($year)
    {
        
    $today  getdate();
        
    $tyear  $today['year'];
        
        
    $age $tyear $year;

        return 
    $age

    but it will still be inaccuarate....any ideas???
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  2. #2

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    I figured it out....here is the function if anyone is interested.
    It will calculate the age for someone born in the year 1 A.D. to now.

    PHP Code:
    function calculate_age($m$d$y)

        
    $now getdate();
        
    $nmonth $now['month'];
        
    $nday   $now['mday'];
        
    $nyear  $now['year'];
        
        if (
    $nmonth $m OR $nmonth $m AND $nday $d) {
            
    $age $nyear $y 1;
        } else {
            
    $age $nyear $y;
        }
        
        return 
    $age

    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width