Calculating the Age from a Date of Birth in PHP


Compute someone’s age based on their date of birth.

Source Code

$birthDate = new DateTime("2000-01-01");
$today = new DateTime("now");
$age = $today->diff($birthDate);
echo $age->y; // Outputs the age
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments