Created
December 10, 2013 18:40
-
-
Save jackabox/7895757 to your computer and use it in GitHub Desktop.
Working out the age from a DOB
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 | |
//date in mm/dd/yyyy format; or it can be in other formats as well | |
$birthDate = '11/05/1992'; | |
//explode the date to get month, day and year | |
$birthDate = explode("/", $birthDate); | |
//get age from date or birthdate | |
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2])); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment