What are the potential pitfalls of manually calculating age based on birthdate in PHP?

One potential pitfall of manually calculating age based on birthdate in PHP is not accounting for leap years, which can lead to inaccuracies in the calculated age. To solve this issue, you can use PHP's built-in DateTime class to accurately calculate age taking leap years into consideration.

$birthdate = "1990-02-29"; // Leap year birthdate
$today = new DateTime();
$diff = $today->diff(new DateTime($birthdate));
$age = $diff->y;

echo "Age: " . $age;