PHP date_diff Function Guide
The date_diff function in PHP is used to calculate the difference between two dates and returns the result in the form of a DateInterval object. Its syntax is as follows:
date_diff(DateTime $datetime1, DateTime $datetime2, bool $absolute = false)
$DateTime1 and $DateTime2 are DateTime objects that represent the two dates for which the difference is to be calculated; $absolute is an optional Boolean parameter used to specify whether to return the absolute value of the difference (ignoring the positive or negative sign).
Example of use:
$date1 = new DateTime('2022-01-01');
$date2 = new DateTime('2022-01-10');
$interval = date_diff($date1, $date2);
echo $interval->format('%R%a days'); // 输出:+9 days
In the example above, we calculated the difference between $date1 and $date2, and then formatted the result into a string using the format method.