1

How to retrieve date from a date field and store it in computed field? I have tried this code:

$start_date = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_start_date')));
$entity_field[1]['value'] = $start_date;

But it displays 'datetime'. I want to retrieve the value.

1

It looks like you're indiscriminately popping values off of the array returned from field_get_items, without checking to see which index you actually need. I haven't tested this but I think you'll have better luck with code like this:

$items = field_get_items($entity_type, $entity, 'field_start_date');

// Use array_shift if you want the FIRST field item
$item = array_shift($items);
// OR
// Use array_pop if you want the LAST field item
$item = array_pop($items);

// Get the date value of the field
$start_date = $item['value'];

// Use start date
$entity_field[1]['value'] = $start_date;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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