How to calculate difference between two dates using Global PHP field? I have a global PHP field provided by views php module. I tried two functions to calculate the date difference, date_diff() and $fieldDate->difference() but it always gives me an ajax error.
I think it causes by date format of the date field but I don't know how to fix it. What is right here?

$today=date("m/d/Y"); 
$load = $data-&gt;field_field_date_loading[0]['raw']['value'];
$diff=date_diff($load,$today);
echo $diff-&gt;format("%R%a days");


or

$today=date("m/d/Y"); 
$load = $data-&gt;field_field_date_loading[0]['raw']['value'];
$diff = $load-&gt;difference($today, 'days');
echo $diff;
The function date() is a formatting function, if you want to use date_diff() your code needs to be something like:

$today = new DateTime();
$load = new DateTime($data-&gt;field_field_date_loading[0]['raw']['value']);
$diff = date_diff($load, $today);