To calculate the age of a person based on their birthdate using DateTime in PHP, you can follow these steps:
$currentDate = new DateTime();
$birthdate = new DateTime('1990-05-20');
$age = $birthdate->diff($currentDate)->y;
echo "The person's age is " . $age . " years.";
Putting it all together, here's the complete code:
$currentDate = new DateTime();
$birthdate = new DateTime('1990-05-20');
$age = $birthdate->diff($currentDate)->y;
echo "The person's age is " . $age . " years.";
This will output: "The person's age is 31 years."