I have the following columns in my table: birth_year, birth_month, birth_day
example data from the table is
birth_year birth_month birth_day
1996 April 1
I only need to get the age of a user.
It doesn't need to be accurate. I just need to subtract the year today and his/her birth_year
example:
his birth_year is 1996
and the date today is 2015
if($row = mysqli_fetch_assoc($query_run)
{
$birth_day = $row['birth_year']; //data from the database which equals to 1996
$today = date("Y"); //year today
$age = $today - $birth_day; //age of this user
echo $age; //this should output 19
}
My problem is the $age
variable from the above echoes a blank or null value.
here are the sources that might be similar to my question:
The difference between my question and those is that I can't follow the format of DateTime
because my registration form looks like this.