1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Calculate time difference

Discussion in 'Community' started by hsmdk, May 10, 2016.

  1. hsmdk

    hsmdk New Member

    Level: Community
    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
    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
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    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
  3. hsmdk

    hsmdk New Member

    Level: Community
    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

  4. hsmdk

    hsmdk New Member

    Level: Community

    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 ?

    PaulT likes this.

Share This Page