根据数据库$day、$month$year计算年龄


calculate age from database $day, $month, $year

我正在尝试计算年龄。我正在使用这段代码,它非常适合示例出生日期,但我无法弄清楚如何让$birthDate等于我的三个单独的变量$day、$month$year存储在我的数据库中为每个用户。我将如何做到这一点$birthDate = $day/$month/$year 并使用下面的年龄计算器?

<?php
$birthDate = "12/17/1983";
$birthDate = explode("/", $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;
?>

这是我的注册系统中尝试和测试的

 //date in mm/dd/yyyy format; or it can be in other formats as well
  $birthDate = $_POST['month']."/".$_POST['date']."/".$_POST['year'];
  //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]));

使用日期时间选择器或验证通过 JavaScript 提交的值以仅允许有效日期