How to count the number of days between two dates (PHP)
If you need to count the number of days between two PHP dates, it is convenient to use DateTime.
Example:
$date1 = DateTime::createFromFormat('d-m-Y', '15-02-2022');
$date2 = DateTime::createFromFormat('d-m-Y', '19-02-2022');
$difference = date_diff($date1, $date2);
$differenceDayCount = $difference->days;
var_dump($differenceDayCount); // 4
Comments