KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to sum a time field
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Mac & Win
Published On: June 8, 2010

The Sum command cannot be used to sum time fields. The following method gets as an argument a pointer to a time field and returns the sum in a time variable:


  `Method name: SumForTimeField
  `Parameters:
  `Input: Pointer to a time field
  `Output: Sum of the time values for the records in selection


C_TIME($0)
C_POINTER($1;$timeField_p)
C_LONGINT($sumValue_l; $index_l)

If(Count parameters >= 1)
  $timeField_p:=$1
  ARRAY LONGINT(arrayTime_al;0)
  SELECTION TO ARRAY($timeField_p->;arrayTime_al)

  For($index_l;1; Size of array(arrayTime_al))
    $sumValue_l:=$sumValue_l + arrayTime_al{$index_l}
  End for

$0:=Time(Time string($sumValue_l))
End if


A sample call for the given method is shown below:

C_TIME($sum)

ALL RECORDS([<Table name>]) ` Creates selection
$sum:= SumForTimeField(->[<table name>]<Field name>)