Jump to content

[SOLVED] getiing age through function...


runnerjp

Recommended Posts

im trying to add my "get users age" code into a function but it displays nothing... any1 know where im going wrong?

 

function

function getage($dob)  {
$birthday = $pdob;

$today = date('d-m-Y');

$a_birthday = explode('-', $birthday);
$a_today = explode('-', $today);

$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];
$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];

$age = $year_today - $year_birthday;

if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}
}

 

the code on the page is

$dob= $getuserprofile['dob'];
he age is <?php getage($dob); echo $age?>

Link to comment
https://forums.phpfreaks.com/topic/134986-solved-getiing-age-through-function/
Share on other sites

also, your function needs to have a return in it, like below...

 

function getage($dob)  {
$birthday = $pdob;

$today = date('d-m-Y');

$a_birthday = explode('-', $birthday);
$a_today = explode('-', $today);

$day_birthday = $a_birthday[0];
$month_birthday = $a_birthday[1];
$year_birthday = $a_birthday[2];
$day_today = $a_today[0];
$month_today = $a_today[1];
$year_today = $a_today[2];

$age = $year_today - $year_birthday;

if (($month_today < $month_birthday) || ($month_today == $month_birthday && $day_today < $day_birthday))
{
$age--;
}

return $age;

}

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.