+3 votes
in Programming Languages by (7.0k points)
I want to find the number of days between two dates. Which PHP function should I use to calculate the difference between two dates?

1 Answer

0 votes
by (29.3k points)

PHP function date_diff() can be used to calculate the difference between two dates.

Here is an example:

<?php
$date1=date_create("2020-6-15");
$date2=date_create("2021-1-12");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");
?>

The above code will return +211 days.

...