It would be very useful, if interval was also stored in seconds, in addition to current 2 columns. My use case is:

I have converted two dates to integers in Rules to be able to calculate difference between them. Now I want to calculate, how many time intervals fit into that difference, so I also need interval as seconds. Conversion is complicated b the fact, that I would need to use conditionals to calculate different values based on interval period.

Comments

milos.kroulik created an issue. See original summary.

milos.kroulik’s picture

Status: Active » Closed (works as designed)

OK, this is not possible by design. Sorry for silly request.

Sylense’s picture

For anyone that should stumble upon this and need a solution I managed to pull this off using a computed field. I needed a way to do sorting and other things and so I converted the interval multiplier and period back to seconds. I simply used the function already provided by Interval (interval_php_interval) to do it. Be sure to change the data type on the computed field from varchar to integer so you can properly sort, etc.

function computed_field_FIELD_COMPUTED_FIELD_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
    $duration = strtotime(interval_php_interval($entity->FIELD_COMPUTED_FIELD['und'][0]), 0);
    $entity_field[0]['value'] = $duration;
}

If you don't want to use a computed field or only want to display the seconds you could also create a custom field formatter and use the same interval_php_interval function in the markup:

'#markup' => check_plain(strtotime(interval_php_interval($item), 0)),