datetime
objects using createFromFormat
static method of DateTime
built-in class$first_date = DateTime::createFromFormat('Y-m-d', "2020-12-23");
$second_date = DateTime::createFromFormat('Y-m-d', "2020-12-30");
Using diff()
method of DateTime
class we actually calculate differences between the two dates and we get the result in days$difference_between_the_days = $second_date->diff($first_date)->format("%a");
echo $difference_between_the_days;