Calculating total time taken to finish a race
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
The following method illustrates how to calculate, time taken by a rider to finish a race.
Terminolgies
- 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[0]['value'];
$stop_time = $stop_time[0]['value'];
$penalties = field_get_items('node', $node, 'field_penalities');
$penalties = $penalties[0]['value'];
$entity_field[0]['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'];
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion