<?php
// If you are using PHP 5.3 or above
$date_1 = new DateTime("2021-09-20");
$date_2 = new DateTime("2021-10-22");
$num_of_days = $date_1->diff($date_2)->format("%a");
echo $num_of_days;
?>
Output
32
You can also use the strtotime() function to calculate the number of days between two dates. You just need to calculate the difference between the given dates and divide them to (60 * 60 * 24).
Code Example
<?php
$date_a = strtotime("2021-03-27");
$date_b = strtotime("2021-04-25");
$diff_in_dates = $date_b - $date_a;
echo round($diff_in_dates / (60 * 60 * 24));
?>
Output
29
0 Comments