Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • CDMS
  • Castor CDMS Calculations Manual
  • Date and time difference templates

Calculate time difference in seconds (using text fields): EDC/CDMS

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • CDMS
    Castor CDMS Manual Castor CDMS Calculations Manual Frequently Asked Questions Articles for Data Managers Castor CDMS Compliance Release Documents
  • eConsent
    Castor eConsent Manual Castor eConsent Compliance Release Documents
  • SMS
    Castor SMS Manual Castor SMS Compliance Release Documents
  • Castor Connect
    Castor Connect Compliance Release Documents Castor Connect Manual Castor Connect - Participant Quick Start Guide
  • Helpdesk
    News Other Resources Castor products knowledge resources
  • Status page
  • Completing a Study
+ More

Time fields in Castor only capture hours and minutes. If you want to capture time in the format HH:mm:ss, you need to use text fields. However, you can calculate with those as well!

To calculate the difference between two text fields where you are capturing time as HH:mm:ss, you can use the following formula:

var timePoint_1 = '{time1}';
var timePoint_2 = '{time2}';
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 diffInSeconds = Math.floor(timeDifference/1000);
diffInSeconds;

Replace time1 and time2 with your own variable names for time and leave the rest as it is.

Check format of time

In addition, you can also use a calculation to check if the formatting of the time that has been entered is correct (since it is free text, you might want to check this) and render a message. For that you can use the following formula:

var time1 = "{time1}";
var time2 = "{time2}";
if (!time1.match(/\d\d:\d\d:\d\d/) || !time2.match(/\d\d:\d\d:\d\d/)) {
 "The previous field does not match the required HH:mm:ss format.";
} else {
 "The previous field was formatted correctly";
};
elapsed time time calculator

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Calculate the difference between two dates: EDC/CDMS
  • Calculate the age using a date variable: EDC/CDMS
  • Check if the difference between two dates is between limits: EDC/CDMS
  • Calculate the age using a year or year and month variable: EDC/CDMS
ISO 27001
FDA - 21 CFR part 11
ICH GCP compliant
HIPAA compliant
CDISC
ISO 9001
gdpr compliant

Products & Industries

  • Electronic Data Capture (EDC)
  • ePRO
  • eConsent
  • Decentralized Clinical Trials (DCT)
  • Clinical Data Management
  • Medical Device & Diagnostics
  • Biotech & Pharma
  • CROs
  • Academic Research

Resources

  • Thought Leadership
  • Blog
  • Castor Academy
  • Knowledge Base

 

Company

  • About Us
  • Careers
  • News
  • Contact Support
  • Contact Us

Legal & Compliance

  • Terms of Use
  • Privacy & Cookie Statement
  • Responsible Disclosure Policy
  • Good Clinical Practice (GCP)
  • ISO Compliance Certificates
  • GDPR & HIPAA Compliance
  • Security Statement

© 2022, Castor. All Rights Reserved.

Follow us on social media


Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand