How can the DateTime::diff function in PHP be utilized to calculate age accurately, as discussed in the forum?

To calculate age accurately using the DateTime::diff function in PHP, you need to calculate the difference between the current date and the birthdate, and then extract the years from the difference. This can be achieved by creating DateTime objects for the current date and the birthdate, calculating the difference, and then accessing the 'y' property of the DateInterval object returned by the diff function.

$birthdate = new DateTime('1990-05-15');
$currentDate = new DateTime();
$age = $birthdate->diff($currentDate)->y;
echo "Age: " . $age;