Follow

Calculating the Time Between Date/Time Selector Fields

You can use a Computed Label field to calculate the time difference between two time picker fields. In the example below, we have a time field with the key "time1" and another with the key "time2". 

In the example below, we calculate the total hours between the two date values.  You can adjust the formula to convert to minutes, seconds or days according to your needs.

//ADD THIS TO YOUR CALCULATION FIELD

var date1 = dateFromString($time1$);
var date2 = dateFromString($time2$);
var hours = Math.abs(date2 - date1) / 36e5;

return hours;

function dateFromString(isoDateString) {
  var parts = isoDateString.match(/\d+/g);
  var isoTime = Date.UTC(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]);
  var isoDate = new Date(isoTime);

return isoDate;
}

Have more questions? Submit a request

Comments

  • Avatar
    ARC Mobile Forms

    Is dateFromString standard Javascript? Is there a list of other examples for Computer label? Would this work:
    if ($select_worker$ = 'Other') { return $OtherWorker$; } else { return $select_worker$; }

  • Avatar
    Andrew Lathrop

    There are many different ways to use a computed label. You can do equations, functions and formatting for date and time, currency, strings, numerics.

    The methodology for that could work depending on what field types you are using and what you are trying to accomplish. The best way for me to help you figure this out is to email me directly at fastfieldsupport@mergemobile.com

Powered by Zendesk