Calculate time difference

hsmdk

New Member
Hi have looked in the wiki about this issue and found other threads about this subject

i have try to code beblow in the a element were i what it to return resault but i only see the code value in the field
upload_2016-5-10_1-51-34.png
Can any one lead me on the right track :)


The code

$starttid=strtotime ('{time_use_3_repeat___starttid} ') ;
$sluttid=strtotime ('{time_use_3_repeat___sluttid} ') ;
$seconds = $sluttid - $startid;

$hours= floor ($seconds/3600);
$minutes = floor ($seconds % 3600/60);
$seconds = $seconds % 60 ;

return sprintf("%02d:%02d", $hours, $minutes);


p.s. have also try with _raw
 
Well, first issue is that you haven't enabled "Eval", so we aren't treating that as PHP code, we're treating it as just text.

Next issue is, defaults only get applied when a form is created, when the page is being loaded. Not when a form is being submitted.

What you probably need is a calc element.

-- hugh
 
Hi Hugh

Thanks for your reply, i have now found the calc elements an try to set the code in that content but et seems not to Work i do get som "wird" resaults




upload_2016-5-12_10-39-33.png
 
Hi

Found away to sovle the issue and here is the code there can do it in the calc plugin

This return the time diffreance as a comma figure

$start_time = '{testlist_repeat_10_repeat___fr1}';
$end_time = '{testlist_repeat_10_repeat___fr2}';

$time1 = new DateTime($start_time);
$time2 = new DateTime($end_time);
$interval = $time1->diff($time2);

$hour= $interval->format('%h');
$min = $interval->format('%i');
$sec = $interval->format('%s');

return $hour+$min /60;

HOWEVER !!! I do not Work in repeat mode it return "undefined" (I testet the same fields in a normal Group and in a repeat Group)

I also testet regular comma fields but here was no problems, i only when i use time fields

Have any one any idear why or is it a Fabrik bug ?

Reagrds
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top