คำนวนอายุ function count_age

posted on 04 Aug 2009 14:12 by poyalo in PHP

function age($dbirth){
list($year,$month,$day)=explode("-",$dbirth);
$mnow=mktime(0,0,0,date("m"),date("d"),date("Y"));
$mold=mktime(0,0,0,$month,$day,$year);
$nm=$mnow-$mold;
$y=(date("Y",$nm)-1970);
if($y!=0){
$y="$y ปี";
}
$m=(date("m",$nm)-1);
if($m!=0){
 $m="$m เดือน";
}
$d=(date("d",$nm)-1);
if($d!=0){
$d="$d วัน";
}
$age="$y$m$d";
return $age;
}

$dbirth2="1976-02-20";
echo age($dbirth2);
?>

edit @ 4 Aug 2009 14:13:12 by พีระพล โภยะโล

Comment

Comment:

Tweet