Hello,

I'm trying to calculate hours difference in my content type. I have "start date" and "end date" when the form is filled. I'm not sure what am I doing wrong, so any help would be appreciated.

Strict warning: Only variables should be passed by reference in eval() (line 1 of /computed_field/computed_field.module(394) : eval()'d code)

Strict warning: Only variables should be passed by reference in eval() (line 2 of /computed_field/computed_field.module(394) : eval()'d code)

Warning: array_pop() expects parameter 1 to be array, boolean given in eval() (line 2 of /computed_field/computed_field.module(394) : eval()'d code).

Here is the code that I'm using for calculation:

$start_date = array_pop(field_get_items($entity_type, $entity, 'field_status_pocetak_prijava')); 
$end_date = array_pop(field_get_items($entity_type, $entity, 'field_status_kraj_prijava'));

$start_date = new DateObject($start_date['value'], ''); 
$end_date = new DateObject($end_date['value'], '');

$duration = $start_date->difference($end_date, 'hours');
$duration = $duration = floor($duration);

$entity_field[0]['value'] = $duration;

Comments

kido created an issue. See original summary.

hosisam’s picture

You should use this

Computed Code (PHP)

$start_value = $entity->field_date[LANGUAGE_NONE][0]['value'];
$end_value = $entity->field_date[LANGUAGE_NONE][0]['value2'];
$timezone = $entity->field_date[LANGUAGE_NONE][0]['timezone'];

$start_date = new DateObject($start_value, $timezone);
$end_date = new DateObject($end_value, $timezone);

$duration = $start_date->difference($end_date, 'hours');

$entity_field[0]['value'] = $duration;

Display Code (PHP)


$display_output = $entity_field_item['value']." hours";

avpaderno’s picture

Status: Active » Fixed
Issue tags: -array_pop, -eval(), -variables

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.