DoB to UNIX format

Discussion in 'PHP' started by k3str3l, May 17, 2007.

  1. #1
    im struggling to write a script that accepts a standard DoB converts it to UNIX format and calculates the age of the person in years to a decimal precision of one point.

    the orginal dob format is DD/MM/YY

    any help is appreciated
     
    k3str3l, May 17, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    a solution will be :

    #reformat date as MM/DD/YY
    $dob = "19/04/76";
    
    $od = split("/", $dob);
    $nd = "{$od[1]}/{$od[0]}/{$od[2]}";
    
    # calculate
    $old_y = (time() - strtotime($nd)) / (365 * 24 * 3600);
    echo number_format($old_y,1);
    
    PHP:
    hope this helps
     
    gibex, May 17, 2007 IP
  3. k3str3l

    k3str3l Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thankyou that has sorted it, much appreciated
     
    k3str3l, May 17, 2007 IP
  4. k3str3l

    k3str3l Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The function only works between a certain date range, i.e it wont give me the correct age for people born in <1946
     
    k3str3l, May 17, 2007 IP
  5. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #5
    yes, because time() has a reference point in january 1st 1970 as stated in php manual:

    so, you will see weird results on dates < 1970

    you have to use another algorithm for your calculations.
     
    gibex, May 17, 2007 IP