This topic is locked

Total of times

11/20/2008 5:04:32 AM
PHPRunner General questions
P
pidejean author

Dear all,
On my list page i can not get the right total of a colunm containing time values.
8:30:00

8:15:00

8:00:00
The total of the 3 values gives me 24 - the right response should have been 24:45:00
Please help me.

J
Jane 11/20/2008

Hi,
unfortunately total, avarage and max functions do not work correct for time fields in the PHPRunner.

As workaround you can calculate it manually.

Here are some tips:

  1. add new List page: Before process event on the Events tab:
    global $total_time;

    $total_time = 0;


2. then calculate total time manually in theList page: After record

processed
event:

global $total_time;

$arr = explode(":",$data["timefield"]);

if ($arr[0])

$ttime = $arr[0];
if ($arr[0] & $arr[1])

$ttime = $arr[0]60+$arr[1];
if ($arr[0] & $arr[1] & $arr[2])

$ttime = $arr[0]
6060+$arr[1]60+$arr[2];
$total_time+=$ttime;


3. and print calculated value on the page in the List page: Before

display
event:

global $total_time;

$hours = floor($total_time/3600);

$minutes = floor(($total_time-$hours3600)/60);

$seconds = $total_time-$hours
3600-$minutes*60;

$total_time = $hours.":".$minutes.":".$seconds;
$record["timefield_total"]=$total_time;

$record["timefield_showtotal"]=true;

$totals_records["data"][]=$record;

$xt->assignbyref("totals_record",$totals_records);



where timefield is your actual field name.
We'll add totals for time field to the next PHPRunner version.