生年月日から年齢を割り出す関数です。下記の関数を利用して
$birthday = birthToAge(1985-12-31);
echo $birthday;
で年齢がわかります!
デモサイトにて確認できます!
スポンサーリンク
1 2 3 4 5 6 7 8 9 10 11 12 13 | //生年月日から年齢変換 function birthToAge($ymd){ $base = new DateTime(); $today = $base->format('Ymd'); $birth = new DateTime($ymd); $birthday = $birth->format('Ymd'); $age = (int) (($today - $birthday) / 10000); return $age; } |