What are some best practices for comparing dates in PHP to determine birthdays?

When comparing dates in PHP to determine birthdays, it is important to consider leap years and handle cases where the birth date might be after the current date in the current year. One approach is to use the DateTime class in PHP to create date objects for the birth date and the current date, and then compare them while taking leap years into account.

// Example code for comparing dates to determine birthdays
$birthDate = new DateTime('2000-02-29'); // Assuming the birth date is February 29, 2000
$currentDate = new DateTime(); // Current date

// Adjust the birth date for leap years
if ($birthDate->format('m-d') !== $currentDate->format('m-d')) {
    $birthDate->modify('last day of February');
}

// Compare the birth date with the current date
if ($birthDate < $currentDate) {
    echo "Birthday has passed this year.";
} elseif ($birthDate > $currentDate) {
    echo "Birthday is yet to come this year.";
} else {
    echo "Happy Birthday!";
}