I am trying to use this age calculator to calculate users' ages, which is stored in a MySQL database. I thought this would work, but it doesn't seem to.
My problem is that I don't know how to get the date, from a users table from MySQL.
<?php
require_once 'core/init.php';
$user = new User();
if(!$user->isLoggedIn()) {
Redirect::to('index.php');
}
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = "<?php escape($user->data()->birthday); ?>"; //"08/13/2000";
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
? ((date("Y") - $birthDate[2]) - 1)
: (date("Y") - $birthDate[2]));
echo "Age is: " . $age;
?>