Monday, January 07, 2008

年齢 MYSQL PHP

select (YEAR(CURDATE())-YEAR(birth))- (RIGHT(CURDATE(),5) <RIGHT(birth,5)) AS age from hoge

----

PHPの場合

<?php
$birthday = '1990-01-12';
$lapse = getdate(mktime()-mktime(0,0,0,substr($birthday,5,2),
substr($birthday,8,2),substr($birthday,0,4)));
$age = $lapse['year']-1990;
echo $age;
?>
~

No comments: