Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
D'Arcy Norman has a Computed Field example in which he calculates the average speed of a bike trip, rather than filling it in manually:
Computed Field settings (leaving other fields at their defaults):
- Computed Code:
$node_field[0]['value'] = ($node->field_distance[0]['value'] / $node->field_duration[0]['value']) * 60;
- Check 'Store using the database settings below
- Data Type: float
- Data Length: 10,2
- Default Value: 0
- Check 'Sortable' to make the field sortable in views.
The end result can then be displayed in a sortable view.
Comments
What is the type of the duration field?
Hello! What is the type of the duration field? I would like to make a speed calculator, but i don't know the type of duration. I would like to use time format, like this: hh:mm:ss
Is it possible?
That is a REALLY good
That is a REALLY good question. I am curious what Darcy used as well... because the Computed Field Module does NOT work with the module, "Duration". I used the Module "HH:MM:SS" and that is working well now.
Unfortunately, it will calculate 6:30 as 6.5... which stinks...