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

chrispooh’s picture

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?

mtconto’s picture

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...