Jump to content

calculate age


Recommended Posts

Hi everyone, im trying to calculate the age of a user using the following code...

  <?php


  function birthday ($row_getdets['dob']{
    list($year,$month,$day) = explode("-",$birthday);
    $year_diff  = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff   = date("d") - $day;
    if ($day_diff < 0 || $month_diff < 0)
      $year_diff--;
    return $year_diff;
  }

?>

 

My code seems to be breaking however and my page dies (outputs nothing) Can anybody see whats wrong? Is it my variable $row_getdets['dob'];

Link to comment
https://forums.phpfreaks.com/topic/202674-calculate-age/
Share on other sites

thanks premiso, Ive just tried  ...

  <?php

   $birthday = $row_getdets['dob']; 

function birthday ($birthday){
    list($year,$month,$day) = explode("-",$birthday);
    $year_diff  = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff   = date("d") - $day;
    if ($day_diff < 0 || $month_diff < 0)
      $year_diff--;
    return $year_diff;
  }

?>

 

to no avail, is this not what you meant?

Link to comment
https://forums.phpfreaks.com/topic/202674-calculate-age/#findComment-1062344
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.