SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Calculating Age

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    England
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating Age

    I have a script I got out of a book that takes a day ($day), a month ($month) and a year ($year) for a date of birth and then outputs the persons age. However if the year is before 1970 the age is always 32. The script uses a timestamp, do these only work on Unix (I am running Windows)?
    Is there another simple, short way of doing this?

    Cheers.

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2002
    Location
    Reykjavik, Iceland
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that the UNIX timestamp was created 1970 ....

  3. #3
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this

    PHP Code:
    <?
    $result 
    mysql_query("SELECT DATE_FORMAT(date, '%Y') AS mydate from table");
    $myrow mysql_fetch_array($result);
    $year $myrow["mydate"];
    $today date("Y");
    $age $today $year;
    echo 
    "$age years old";
    ?>
    http://redgoals.com ... my site ... nuff said

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    England
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers redgoals

    I adapted the code you posted to take into account the day and month and it does the job fine.

    Thanks again.


Bookmarks

Posting Permissions

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