What are common issues when calculating date differences in PHP using mktime?

One common issue when calculating date differences in PHP using mktime is handling daylight saving time changes, which can affect the accuracy of the calculation. To solve this issue, it's recommended to use the DateTime class in PHP, which automatically adjusts for daylight saving time.

$date1 = new DateTime('2022-01-01');
$date2 = new DateTime('2022-01-15');

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