The following method illustrates how to calculate, time taken by a rider to finish a race.
- Time taken(field_time_taken): Time taken by a rider to finish the race, which is an arithmetic operation of start time, stop time and penalities.
- Start time(field_start_time): The start time of the race.
- Stop time(field_stop_time): Time at which the rider finishes the race.
- Penalties(field_penalties): Penalties(in seconds).
So Time taken = Stop time - Start time + Penalties
In Drupal 7, $node variable can no longer be used instead $entity has to be used.
The following code, would go into the "Computed Code(PHP)" section of the field settings.
$node = menu_get_object();
$start_time = field_get_items('node', $node, 'field_start_time');
$stop_time = field_get_items('node', $node, 'field_stop_time');
$start_time = $start_time['value'];
$stop_time = $stop_time['value'];
$penalties = field_get_items('node', $node, 'field_penalities');
$penalties = $penalties['value'];
$entity_field['value'] = $stop_time - $start_time + $penalties;
The following code would go into "Display Code (PHP)" section of the field settings.
$display_output = $entity_field_item['value'];