public static function getAge($dob, $date_of_death = null, $check_date = null)
{
if (!$dob) {
return 'Unknown';
}
$dob_datetime = new DateTime($dob);
$check_datetime = new DateTime($check_date);
if ($date_of_death) {
$dod_datetime = new DateTime($date_of_death);
if ($check_datetime->diff($dod_datetime)->invert) {
$check_datetime = $dod_datetime;
}
}
return $dob_datetime->diff($check_datetime)->y;
}
public function getProfile() { $db = new DB(); $sql = "SELECT * FROM " . self::$profile_table . " WHERE id=:id"; $profile = $db->query($sql, [':id' => $this->id]); foreach ($profile[0] as $key => $val) { if ('id' == $key) { continue; } $this->{$key} = $val; } $this->age = Helper::getAge($this->birthday); }