Last active
December 15, 2015 02:29
-
-
Save phenix-factory/5187561 to your computer and use it in GitHub Desktop.
PHP: renvoie l'age en fonction d'une date.
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 | |
/* | |
* 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