What potential pitfalls should be considered when subtracting dates in PHP, as seen in the code provided?
When subtracting dates in PHP, potential pitfalls to consider include handling different date formats, timezones, and daylight saving time changes. To ensure accurate date subtraction, it's important to standardize the date formats and consider using PHP's DateTime class to handle timezone conversions and daylight saving time adjustments.
$date1 = new DateTime('2022-01-15');
$date2 = new DateTime('2022-01-10');
$interval = $date1->diff($date2);
echo $interval->format('%R%a days');