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?

$load = $data->field_field_date_loading[0]['raw']['value'];
echo $diff->format("%R%a days");


$load = $data->field_field_date_loading[0]['raw']['value'];
$diff = $load->difference($today, 'days');
echo $diff;

1 Answer 1


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->field_field_date_loading[0]['raw']['value']);
$diff = date_diff($load, $today);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.