Calculating the difference using a date and a time field: EDC/CDMS
If you are storing date and time in separate variables, use the template below to calculate the difference between a date and a time field and display the difference in hours:
var d1 = moment('{date1}' + ' ' + '{time1}').format("DD-MM-YYYY HH:mm"); var d2 = moment('{date2}' + ' ' + '{time2}').format("DD-MM-YYYY HH:mm"); var date_1 = moment(d1); var date_2 = moment(d2); date_2.diff(date_1, 'hours')
Check the calculation template in the calculation helper tool here.
The result will be displayed as follows in the data entry view: