how to calculate the date of birth by giving the date, month, year in the registration page

5
Contributors
4
Replies
7
Views
11 Years
Discussion Span
Last Post by proDharm

Is that a thought, or a request?

If it's a request, you'll have to explain your desire quickly and show some effort. Something along the lines of "I want to do X, but I'm not sure how. Can someone suggest a way to me?" or "I want to do X, tried Y, but got Z. How can I do X?"

I believe you want to calculate the age if teh date of birth is given:

If that is the case you can use the following function:

``````function persons_age(\$year, \$month, \$day)
{

//list(\$year, \$month, \$day) = split('[-.]', \$BirthDate);

\$tmonth = date('n');
\$tday = date('j');
\$tyear = date('Y');
\$years = \$tyear - \$year;
if (\$tmonth <= \$month)
{
if (\$month == \$tmonth)
{
if (\$day > \$tday)
\$years--;
}
else
\$years--;
}
return \$years;
}
``````

Edited by happygeek: fixed formatting

Is there a way to determine the year of birth based on the age given? Also, is there a way to tell the function that the year you want to base the age on is 1992? As if the current year was 1992. Does that make sense?

``````\$dob="1980-07-31"; \$today=date("Y-m-d");
list(\$y,\$m,\$d)=explode('-',\$dob);
list(\$ty,\$tm,\$td)=explode('-',\$today);
if(\$td-\$d<0){
\$day=(\$td+30)-\$d;
\$tm--;
}
else{
\$day=\$td-\$d;
}
if(\$tm-\$m<0){
\$month=(\$tm+12)-\$m;
\$ty--;
}
else{
\$month=\$tm-\$m;
}
\$year=\$ty-\$y;
echo \$year ." year, ". \$month ." months and  ". \$day. " Days";``````

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.