This calculation needs certain things to be completed in the form fields in order to work.
Object names of target fields:
- Start Time = [startTime_1]
- Finish Time = [finishTime_1]
- Start Date = [startDate_1]
- Finish Date = [finishDate_1]
Other things to always remember:
- The "Advanced Calculation" setting must be selected in the calculation field settings.
- All Time / Date fields used in the calculation must be set to "Required" in the field settings
Use the below code in the calculation field
"[startDate_1]"; "[finishDate_1]";
"[startTime_1]"; "[finishTime_1]";
var startdate = (strtotime(`${formObject.returnObjectSP("startDate_1", this.repeatedCount)[0].getValue()} ${formObject.returnObjectSP("startTime_1", this.repeatedCount)[0].getValue()}`)); var enddate = (strtotime(`${formObject.returnObjectSP("finishDate_1", this.repeatedCount)[0].getValue()} ${formObject.returnObjectSP("finishTime_1", this.repeatedCount)[0].getValue()}`)); var timediff = myNS.helper.time_diff( date('Y/m/d H:i', startdate), date('Y/m/d H:i', enddate) ); value = (timediff.days * 24) + (timediff.hours + ((timediff.minutes / 60)));
Once added to the form, this will display as below:
Where the time calculation is only for days and does not include time fields, the following then applies.
Use the below code in the calculation field
"[startDate_1]"; "[finishDate_1]";
var startdate = (strtotime(formObject.returnObjectSP("startDate_1", this.repeatedCount)[0].getValue())-0); var enddate = (strtotime(formObject.returnObjectSP("finishDate_1", this.repeatedCount)[0].getValue())-0); var timediff = myNS.helper.time_diff( date('Y/m/d H:i', startdate), date('Y/m/d H:i', enddate) ); value = (timediff.days);
Once added to the form, this will display as below: