Skip to content

Instantly share code, notes, and snippets.

@phenix-factory
Last active December 15, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phenix-factory/5187561 to your computer and use it in GitHub Desktop.
Save phenix-factory/5187561 to your computer and use it in GitHub Desktop.
PHP: renvoie l'age en fonction d'une date.
<?php
/*
* Calcule l'age en fonction de la date de naissance
* Format de date type 12/06/1988
*/
function age($date) {
/*
* Cette adaptation est obligatoire si on utilise un format de date "Français",
* strtotime ne supporte que le format d-m-Y et pas d/m/Y.
*/
$date = str_replace('/', '-', $date);
return (int) ((time() - strtotime($date)) / 3600 / 24 / 365);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment