-2

I have a database in SQL with name, dob set as a date. I need to display the age of entries to the user.

I have the following

while($row = mysqli_fetch_assoc($sql)) {
    echo $row["Name"]. " " .$row["DOB"]. ";
}

How can i add a column with the age calucated from the DOB.

Thanks

joe
  • 7
  • 4

1 Answers1

0
$dob = new DateTime($row["DOB"]);
$today   = new DateTime('today');
echo $dob->diff($today)->y . " years old";
Lambasoft
  • 909
  • 2
  • 14
  • 33