Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.