+4 votes
in Programming Languages by (59.8k 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

+1 vote
by (353k points)
selected by
 
Best answer

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.


...