From PHP5.3+ has a new built-in functions date_diff to calculate days between two dates. This function gives us more correct results over other custom methods.
$date1 = new DateTime("2023-02-16"); // for current date DateTime("now");
$date2 = new DateTime("2023-02-11");
$days = $date1->diff($date2)->d;
echo "Number of Days: $days";
Number of Days: 5
To find the difference between today use $date1 = new DateTime(“now”);
like wise for difference in years and month you can use
$days = $date1->diff($date2)->m;
$days = $date1->diff($date2)->y;
Older PHP versions (PHP < 5.3) ➥
In Older PHP version we have to do it manually
$diff_days = strtotime("2023-02-16") - strtotime("2023-02-11");
$days = round($diff_days / (60 * 60 * 24));
echo "Number of Days: $days";
Number of Days: 5
Tip: To find the difference between today use $diff_days = strtotime(“2023-02-16”) - time();