Created
September 6, 2015 22:10
-
-
Save vhdm/2978f03efe05dec51372 to your computer and use it in GitHub Desktop.
Age calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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