Calculate time difference in hh:mm:ss (using text fields): EDC/CDMS
Time fields in Castor only capture hours and minutes. If you would like to capture time in the format hh:mm:ss, you will need to use text fields. However, you can calculate with those as well.
To calculate the difference in time between two text fields that use hh:mm:ss, you can use the following template. The output will give the time difference in hh:mm:ss.
var timePoint_1 = '{text1}'; var timePoint_2 = '{text2}'; var split_1 = timePoint_1.split(':'); var split_2 = timePoint_2.split(':'); var date1 = new Date(0, 0, 0, split_1[0], split_1[1], split_1[2]); var date2 = new Date(0, 0, 0, split_2[0], split_2[1], split_2[2]); var timeDifference = new Date(date2 - date1); var diff = Math.floor(timeDifference/1000); var hours = Math.floor(diff/3600); var minutes = Math.floor((diff-(hours*3600))/60); var seconds = diff-(hours*3600)-(minutes*60); if(hours < 10){ hours = "0" + hours; } if(minutes < 10){ minutes = "0" + minutes; } if(seconds < 10){ seconds = "0" + seconds; } hours + ":" + minutes + ":" + seconds;
Replace text1 and text2 with your own variables