What are some alternative approaches to calculating date differences in PHP that do not involve iterating over each day individually?

When calculating date differences in PHP, one alternative approach is to use the DateTime class, which provides built-in methods for calculating differences between dates without iterating over each day individually. This can simplify the process and make the code more efficient.

$startDate = new DateTime('2022-01-01');
$endDate = new DateTime('2022-01-31');

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