Jump to content

[SOLVED] Determining birth year


twilitegxa

Recommended Posts

Or somehow set the date to March 23, 1992.

 

Then take their age, and based on what month and day they put in the form, to figure out what year they were born. Like:

 

If Serena was born on June 30 and is 13

 

then a calculation could be something like this:

 

1992-13 = 1979

June 30 is after March 23, so she has had her birthday this year (1992).

 

But if Raye was born on March 17 and is 13

 

1992 -13 = 1979

but since March 17 is BEFORE March 23, she has not had her birthday yet, and is her birthday year is actually 1978.

 

Does that help at all?

June 30 is after March 23, so she has had her birthday this year (1992).

 

But if Raye was born on March 17 and is 13

 

1992 -13 = 1979

but since March 17 is BEFORE March 23, she has not had her birthday yet, and is her birthday year is actually 1978.

 

Surely that's completely the wrong way round? :s March 17 is before march 23 therefore, on march 23, she HAS had her birthday. And vise versa for the t'other example?

 

Anywho, i'd do it like this:

 

$age = 13;
$mod = '03';//march - note that this must be a string and must be two digits
$dob = '17';

$yob = ('0323' > $mod.$dob) ? 1992 - $age : 1992 - $age - 1;
echo $yob;

Adjusting my previous code

<?php
function yearOfBirth ($day, $month, $age)
{
    $now = strtotime('1992-03-23');

    $yob = date('Y', $now) - $age;
    
    if (date('md', $now) < sprintf('%02d%02d', $month, $day)) $yob--;
    
    return $yob;
}

$year =  yearOfBirth($_POST['birthdateday'], $_POST['birthdatemonth'], $_POST['age']);

echo $year;
?>

  • 9 months later...

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.