Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created April 1, 2020 09:17
Show Gist options
  • Select an option

  • Save morgyface/b718daf485eeb68a6e89d6ca6a7f45d8 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/b718daf485eeb68a6e89d6ca6a7f45d8 to your computer and use it in GitHub Desktop.
PHP | Age from date
<?php
// Return age in years from date of birth
function get_age( $date_of_birth = 0 ) {
$age = null;
if( strtotime( $date_of_birth ) ) {
$date_today = new DateTime('today');
$date_of_birth = new DateTime($date_of_birth);
$age = $date_of_birth->diff($date_today)->y;
}
return $age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment