1. ## Adding + 13 years to a date variable.

Hey guys,

i store the users birthdate in a field in my members table. It is a date type, and i'm trying to make a section of the site which is only for 18+.

Date is stored like this

YYYY/MM/DD

I grab the value from the DB and then i want to add 18 years to the current date so i can do this

\$birthdate = \$birthdate + 18 years.
\$currentdate = date("Y-m-d");
if(\$birthdate > \$currentdate) {
"You are not 18";
}

So i guess i just need to know how to add 18 years to the variable :X

Any help? thanks

2. Use this function to calculate age
PHP Code:
``` function getage(\$strdate) {     \$dob = explode("/",\$strdate);     if(count(\$dob)!=3)     {       return 0;     }     \$y = \$dob[0];     \$m = \$dob[1];     \$d = \$dob[2];     if(strlen(\$y)!=4)     {       return 0;     }     if(strlen(\$m)!=2)     {       return 0;     }     if(strlen(\$d)!=2)     {       return 0;     }   \$y += 0;   \$m += 0;   \$d += 0;   if(\$y==0) return 0;   \$rage = date("Y") - \$y;   if(date("m")<\$m)   {     \$rage-=1;        }else{     if((date("m")==\$m)&&(date("d")<\$d))     {       \$rage-=1;     }   }   return \$rage; }  ```

3. Thanks a lot

4. that's way too complicated

PHP Code:
``` \$d = '1980/11/24';echo date('y-m-d', strtotime('+18 years', strtotime(\$d)));  ```
Might be a better idea to store whether or not the user is over 18 in the session/cookie when they login

5. Originally Posted by galen
that's way too complicated

PHP Code:
``` \$d = '1980/11/24'; echo date('y-m-d', strtotime('+18 years', strtotime(\$d)));  ```
Might be a better idea to store whether or not the user is over 18 in the session/cookie when they login

Try his response Alot cleaner/easier.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•