I am trying to create an age function where the user enters the year they where born into a database through a form and later when they return to their profile page it tells them how old they are by subtracting todays date from the date they were born which will be their current age. How do I subtract my server variable to my time variables? (in red) it just keeps printing it out on the screen or giving me an error. My code looks like this <?php $loginusername = testname; //Get date $date=getdate(date("U")); //query mysql_select_db($database_username, $username); $query_profile = "SELECT * FROM UserNames WHERE username = '$loginusername'"; $profile = mysql_query($query_profile, $username) or die(mysql_error()); $row_profile = mysql_fetch_assoc($profile); $totalRows_profile = mysql_num_rows($profile); //get age ?> <html> <body> <?PHP echo $age = $row_profile['year'] - $date[year]; ?> </body> </html> Thanks in advance. ~Imozeb
I know but could you just help me with this one script, how do I subtract my server variables from my time variables?
I don't know the structure of your database. Maybe this example will help you: <?php //Get date $date=date('Y'); $row_profile['year']=2005; ?> <html> <body> <?PHP echo $row_profile['year'] - $date;?> </body> </html> PHP: