I have 2 DateTime objects. One which represents 2 days from now and the other which represents 2 days and 6 months from now.
I need to be able to count the number of days between these two dates to display to users which dates they can book on.
I have calculated the two dates successfully but I am struggling finding a way to subtract them and return the difference in days.
$first; // first datetime object
$second; // second datetime object
$diff = $first->diff($second);
echo $diff->days;
Also take a look at DateInterval class at php.net
another way is:
$datetime1; //first date
$datetime2; //second date
$dayDiff = date_diff($datetime1, $datetime2);
echo $days;