Skip to content

Instantly share code, notes, and snippets.

@vhdm
Created September 6, 2015 22:10
Show Gist options
  • Save vhdm/2978f03efe05dec51372 to your computer and use it in GitHub Desktop.
Save vhdm/2978f03efe05dec51372 to your computer and use it in GitHub Desktop.
Age calculator
<?php
function birthday($birthday){
$age = strtotime($birthday);
if($age === FALSE){
return FALSE;
}
list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
$now = strtotime("now");
list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
$age = $y2 - $y1;
if($m2-$m1 < 0 || $d2-$d1 > 0)
$age--;
return $age;
}
echo birthday('1987-02-08');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment