For calculating the day difference between two dates using Php. we already have a function for this in Php which can give us the date difference, the Function Named as date_diff().
So, let's look into the PHP date_diff() function basics and what are the parameters required to for the execution of the PHP date_diff() function.
Basic Syntax:
date_diff(datetime1, datetime2, absolute)
In PHP date_diff() function first, two parameters are required and the third one is optional.which accepts the boolean value and by default, it's 'False'.
Let's take example to see the difference between dates:
<?php
$startdate = date_create("2020-03-24");
$enddate = date_create("2020-04-22");
$difference = date_diff($date1, $date2);
echo $difference->format("%R%a days");
?>
Output:
+29 days