What are some common bugs or issues related to the date_diff function in PHP?

One common issue with the date_diff function in PHP is that it may not calculate the difference between dates accurately when the dates are in different timezones. To solve this issue, you can set the timezone for both dates to the same timezone before calculating the difference.

$date1 = new DateTime('2022-01-01', new DateTimeZone('UTC'));
$date2 = new DateTime('2022-01-15', new DateTimeZone('UTC'));
$date2->setTimezone(new DateTimeZone('UTC'));

$interval = $date1->diff($date2);
echo $interval->format('%R%a days');