Created
April 4, 2012 13:45
-
-
Save MauMaGau/2301132 to your computer and use it in GitHub Desktop.
PHP: date to age
This file contains hidden or 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 | |
/* Date to Age */ | |
if( | |
isset ($data['day']) && isset($data['month']) && isset($data['year']) && | |
is_numeric($data['day']) && | |
is_numeric($data['month']) && | |
is_numeric($data['year']) | |
){ | |
$birth = strtotime($data['year'].'-'.$data['month'].'-'.$data['day']); | |
$age_in_seconds = time() - $birth; | |
$age = floor($age_in_seconds / 31556926); // 31 556 926 seconds in year | |
}else $age = 'undetermined'; | |
echo $age; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment