Skip to content

Instantly share code, notes, and snippets.

@MauMaGau
Created April 4, 2012 13:45
Show Gist options
  • Save MauMaGau/2301132 to your computer and use it in GitHub Desktop.
Save MauMaGau/2301132 to your computer and use it in GitHub Desktop.
PHP: date to age
<?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