How to Calculate Age from Date of Birth in PHP

Some web applications are needed to show the age of the user. In that case, you need to calculate the user age from date of birth. Here we’ll provide a short PHP code snippet to calculate age from date of birth.

In the following code, date(), date_create(), and date_diff() functions are used to calculate age of the user till today in PHP.

$dateOfBirth "17-10-1985";
$today date("Y-m-d");
$diff date_diff(date_create($dateOfBirth), date_create($today));
echo 
'Age is '.$diff->format('%y');

Use the above code to get the age from date of birth using PHP date functions.

21 Comments

  1. Anoop Said...
  2. NIKHIL VALSAN Said...
  3. Pankaj Hatwar Said...
  4. Imran Said...
  5. Ruhith Said...
  6. Sarkari Exam Said...
  7. Jobaidul Islam Said...
  8. Ashay Said...
  9. Liverty Said...
  10. Aman Said...
  11. NavneetG Said...
  12. Cheryl Said...
  13. Vaibhav Said...
  14. AK Said...
  15. Krishna Ballabh Gupta Said...
  16. Sourabh Said...
  17. RWS Said...
  18. Yeabsira Said...
  19. Janen R Said...
  20. Jabir Said...
  21. Akash Said...

Leave a reply

keyboard_double_arrow_up