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 the difference between two datetime 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

Use the templates below to calculate the difference between two date time fields. Replace datetime1 and datetime2 with your own variable names.

If you want to round your numbers, replace m3 with:

m3.toFixed(X);

with X being the number of decimals. See also: Rounding numbers.

In minutes

var m1 = moment('{datetime1}', 'DD-MM-YYYY HH:mm');
var m2 = moment('{datetime2}', 'DD-MM-YYYY HH:mm');
var m3 = m2.diff(m1, 'minutes');
m3;

In hours

var m1 = moment('{datetime1}', 'DD-MM-YYYY HH:mm');
var m2 = moment('{datetime2}', 'DD-MM-YYYY HH:mm');
var m3 = m2.diff(m1, 'minutes');
m3/60;

In days

var m1 = moment('{datetime1}', 'DD-MM-YYYY HH:mm');
var m2 = moment('{datetime2}', 'DD-MM-YYYY HH:mm');
var m3 = m2.diff(m1, 'minutes');
m3/1440;

Using separate date and time fields

If you are using separate fields for dates and times, use the template below to calculate the difference in minutes:

var m1 = moment('{date1}' + ' ' + '{time1}', 'DD-MM-YYYY HH:mm');
var m2 = moment('{date2}' + ' ' + '{time2}', 'DD-MM-YYYY HH:mm');
var m3 = m2.diff(m1, 'minutes');
m3;
time delta datetime subtraction

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Calculate time difference between two time fields: EDC/CDMS
  • Calculate the difference between two dates: EDC/CDMS
  • Calculate the age using a year or year and month variable: EDC/CDMS
  • Calculate time difference in seconds (using text fields): 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