php - Calculate date difference in Drupal views -
i need calculate difference between 2 date fields in drupal 7 views. how do this? have installed views php can not figure out how date fields works. have search , tried snippets give up. 2 date fields in node are: start: 2016-02-06 07:15 slut: 2016-02-09 16:15 code snippet have tried is:
$start=$row->field_start; $slut=$row->field_slut; $diff=$slut-$start; print_r($diff);
this result in 0. values 2 variables both 4 when them in views php field? have tried both date , date (unix timestamp) same result. /chrotto
you can try this:
// make sure values getting here correct $start_value = $row->field_start; $end_value = $row->field_slut; $start_date = new dateobject($start_value); $end_date = new dateobject($end_value); $duration = $start_date->diff($end_date);
Comments
Post a Comment