How to calculate Age from Date of Birth in PHP?
In this post, we will give you very simple example how to calculate age from date of birth in PHP.
1. Code:
<?php
function caculateAgeFromDateOfBirth($dateOfBirth){
$age = (date('Y') - date('Y',strtotime($dateOfBirth)));
return $age;
}
$dateOfBirth = "1992-07-02";
echo caculateAgeFromDateOfBirth($dateOfBirth);
?>
2. Example
Input:
dateOfBirth = "1992-07-02"
Output:
output: 30