In this answer, I have shared how to calculate age from dob in PHP programming language. Calculate age from date of birth using PHP
Copy the below PHP program and change the $birthDate
variable value to your own dob and calculate your age.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php /** * Date in mm/dd/yyyy format; or it can be in other formats as well. */ $birthDate = "12/17/1983"; //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])); echo "Age is:" . $age; ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.