I have found various methods to calculate the number of dates between 2 dates by first using date_create()
and passing it the dates (without time) and then using ->diff
on one of the them and works perfectly fine.
However when I attempt to do some integer related operations on it, such as comparing it if difference is >0 then it shows an error :
Object of class DateInterval could not be converted to integer
I have used var_dump() and it shows the value in it stores as string, but intval()
is also not successful over it. Any other way to change it to integer?
Code is as follows:
$d1 = date_create(); //get current server time
$d2 = date_create("2020-02-01");//some future date
$diff = $d1->diff($d2);
echo $diff->days; //works fine & displays result perfectly
if($diff->days > 30) {echo "month of difference";} //error here