MyBB Community Forums

Full Version: [F] Birthday bug (again?)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hello,

I just looked at my profile.

Birthday: 16-08-1989 (18 years old) and I'm only 17. Smile
Birthday: Saturday, November 18th, 1978 (29 years old)

mine is off as well

seems like they are calculating the year you are turning 29 even though its not the date yet
No, I was using that fixed file, Tikitiki.
This Fix is from Michael83. He post it in german myBB.

Open member.php and search:
$lang->membdayage = sprintf($lang->membdayage, ($year - $membday['2'])); 

replace with:

$lang->membdayage = sprintf($lang->membdayage, ($year - $membday['2'] - 1));
i am still alive Wrote:This Fix is from Michael83. He post it in german myBB.

Open member.php and search:
$lang->membdayage = sprintf($lang->membdayage, ($year - $membday['2'])); 

replace with:

$lang->membdayage = sprintf($lang->membdayage, ($year - $membday['2'] - 1));

Tested ::

For ex. i fill in as bday [ 20 January 1985 ]
result :: 21y (should be 22)

Edit ::

I've changed the thing into ... and seems to work =P
			$age = get_age($memprofile['birthday']);
			$lang->membdayage = sprintf($lang->membdayage, $age);
Great. Now we're back to the original code...
Fixed.

(You may also download the two attached files and replace inc/functions.php and ./member.php with them.
Instructions for fixing.

Open up inc/functions.php and find:
function get_age($birthday)
{
        $bday = explode("-", $birthday);
        if($bday[2] < 1970)
        {
                $years = 1970-$bday[2];
                $year = $bday[2]+($years*2);
                $stamp = mktime(0, 0, 0, $bday[1], $bday[0], $year)-($years*31556926*2);
        }
        else
        {
                $stamp = mktime(0, 0, 0, $bday[1], $bday[0], $bday[2]);
        }
        $age = floor((time()-$stamp)/31556926);
        return $age;
}

Replace with:
function get_age($birthday)
{
	$bday = explode("-", $birthday);
	if(!$bday[2])
	{
		return;
	}

	list($day, $month, $year) = explode("-", my_date("j-n-Y", time(), 0, 0));

	$age = $year-$bday[2];

	if(($month == $bday[1] && $day < $bday[1]) || $month < $bday[1])
	{
		--$age;
	}
	return $age;
}

Open member.php and find:
$lang->membdayage = sprintf($lang->membdayage, ($year - $membday['2']));

Replace with:
$lang->membdayage = sprintf($lang->membdayage, get_age($memprofile['birthday']));
Not fixed =P
If you enter 14 May 1985 , it returns 21y ! ( should be 22 )
If the month is different from the one it actually is ex. you enter 14 March 1985 , it returns 22y. And 14 September 1985 returns 21y, that's correct =P

Edit ::

This
	if(($month == $bday[1] && $bday[1] < $day) || $month < $bday[1])

Should become
	if(($month == $bday[1] && $bday[0] > $day) || $month < $bday[1])
[edit] That'll teach me for forgetting to submit the Quick Reply form for 20 minutes. Rolleyes

Actually it didn't - it caused wrong ages to be displayed.

There was a typo in what I pasted above.
if(($month == $bday[1] && $bday[1] < $day) || $month < $bday[1])

Should be:
if(($month == $bday[1] && $day < $bday[0]) || $month < $bday[1])
Pages: 1 2 3