What potential pitfalls should be considered when calculating date differences in PHP?

When calculating date differences in PHP, one potential pitfall to consider is the handling of daylight saving time changes. If the dates being compared fall on either side of a daylight saving time change, the difference may not be accurately calculated. To solve this issue, it is recommended to use the DateTime object in PHP, which automatically adjusts for daylight saving time changes.

$date1 = new DateTime('2022-03-12');
$date2 = new DateTime('2022-03-13');
$interval = $date1->diff($date2);
echo $interval->format('%R%a days');