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 dates: 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

Table of Contents

1. getDateDiff 2. Date difference with Moment objects 3. Date difference with today 4. Converting number of days to number of weeks and days 5. Calculating the difference between two dates using date and time field 6. Calculating the difference in two dates in months and remaining days. 

There are multiple options to calculate the difference between dates.

1. getDateDiff

The easiest approach is to use getDateDiff. See this calculation:

getDateDiff('{date2}','{date1}','y')

In this calculation:

  • '{date2}' = the variable name of the date field that contains the most recent date

  • '{date1}' = the variable name of the date field with the older date

  • 'y' = the unit in which the difference is returned, i.e. 'years' in this case

Replace date1 and date2 with your own variable names. Make sure to keep the '{ }' (curly brackets surrounding the variables and the quotation marks). You can change 'y' to any unit you want to use:

  • Year: 'y'

  • Day: 'd'

  • Hour: 'h'

  • Minutes: 'm'

2. Date difference with Moment objects

You can also create Moment objects and then calculate the difference:

var admission = moment('{date1}', 'DD-MM-YYYY');
var discharge = moment('{date2}', 'DD-MM-YYYY');
discharge.diff(admission, 'days');

Instead of days you can also use: 'months', 'years', or 'weeks' depending on what you would like to measure. Check this template in the calculation helper.

3. Date difference with today

You can also calculate the difference between now (today) and a date of choice, e.g. if you want to know how many days passed between today and the date the patient had their last visit:

var dateofvisit = moment('{visit}', 'DD-MM-YYYY');
var today = moment();
today.diff(dateofvisit, 'days');

In this calculation '{visit}' is the variable name of the date of the visit. Replace this variable with your own variable. Check this template in the calculation helper.

Note: This calculation will always update when you open the step where it is located in a record, since it calculates the actual moment at the time you are in that step.

4. Converting number of days to number of weeks and days

If the number of days is known, it is possible to easily convert the number of days to the number of the weeks with the following template:

var amountWeeks = {amountDays}/7
var remainingDays = {amountDays}%7;
remainingDays = remainingDays.toFixed(0)
Math.floor(amountWeeks) + " weeks, " + (remainingDays) + " days"

In this calculation {amountDays} is the variable in which the number of days is collected. Test this template using the calculation helper.

5. Calculating the difference between two dates using date and time field

If you are using a date and time field and would like to output the difference between the two dates in days, hours and minutes, use the following template:

var m1 = moment('{admission}', 'DD-MM-YYYY HH:mm');
var m2 = moment('{discharge}', 'DD-MM-YYYY HH:mm');
var m3 = m2.diff(m1,'minutes');
var m4 = m2.diff(m1,'h');
var numdays = Math.floor(m3 / 1440);
var numhours = Math.floor((m3 % 1440) / 60);
var numminutes = Math.floor((m3 % 1440) % 60);
numdays + " day(s) " + numhours +"h " + numminutes +"m";

This calculation will output the difference in the following format:

6. Calculating the difference in two dates in months and remaining days. 

If you are storing dates in separate variables, use the template below to calculate the difference between the date fields and display the difference in months and remaining days.

var date1 = moment('{date1}', 'DD-MM-YYYY');
var date2 = moment('{date2}', 'DD-MM-YYYY');
var months = date2.diff(date1, 'months');
date1.add(months, 'months');
var days = date2.diff(date1, 'days');
months + ' ' + 'Month(s)'+ ' ' + days + " Day(s)"

Check the calculation template in the calculation helper tool here.

The results will be displayed as follows in the data entry view:


edc/cdms date difference

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • 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
  • Calculate time difference in seconds (using text fields): EDC/CDMS
  • Calculate time difference between two time 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