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 age using a year or year and month variable: 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

Calculate the age of a patient from a birth year Calculate the age from a birth year and a month using a text field Calculate the age of a patient from the birth year and a visit date Calculate the age of a patient from a birth year and display it in years in months Calculate the age of a patient from a birth year and birth month and display age in years

As a full birth date might be considered personally identifiable information, using only the birth year or year and month of birth is a good alternative. It is still possible to calculate the age from these variables using a calculation field (although with less precision).

Calculate the age of a patient from a birth year

var a = moment();
var b = moment('{dem_pat_birthyear}', 'YYYY');
var diff = a.diff(b, 'years'); // calculates patient's age in years
diff; // this prints out the age

In this calculation {dem_pat_birthyear} will need to be replaced with your variable name for birth year.

Note: In the first line, moment(); is used to automatically calculate today's date. This date will be updated once the data entry for a record is opened.

Calculate the age from a birth year and a month using a text field

If you are using a text field to collect only month and year of birth, you can use the following template to calculate the age:

var a = moment();
var b = moment('{dem_pat_birthyear}', 'MM-YYYY');
var age = moment.duration(a.diff(b));
var years = age.years();
var months = age.months();
"The age is " + years + " years " + months + " months ";

In this calculation {dem_pat_birthyear} will need to be replaced with your variable name for birth year.

Calculate the age of a patient from the birth year and a visit date

var birthyear = moment('{patient_birthyear}', 'YYYY');
var visitdate = moment('{baseline_visit}', 'DD-MM-YYYY');
visitdate.diff(birthyear, 'y');

In this calculation {patient_birthyear} will need to be replaced with your variable name for birth year and {baseline_visit} for the visit date. Test this calculation in the calculation helper.

Calculate the age of a patient from a birth year and display it in years in months

When you want to show age in years and months, for example for children, you can use the following formula.

var date1 = "{dob}".split("-");
var jsdate1 = new Date(date1 [2], date1 [1]-1, date1 [0], 0, 0, 0);
var date2 = "{visit_date}".split("-");
var jsdate2 = new Date(date2 [2], date2 [1]-1, date2[0], 0, 0, 0);
var diff = Math.floor(jsdate2.getTime() - jsdate1.getTime());
var day = 1000 * 60 * 60 * 24;
var days = Math.floor(diff/day);
var months = Math.floor(days/31);
var years = Math.floor(months/12);
months = months - (12*years)
years + " years, "+ months + " months";

You can test this template in the calculation helper.

Calculate the age of a patient from a birth year and birth month and display age in years

var string = '{birthmonth}' + '-' + '{birthyear}';
var dob = moment(string, 'MM-YYYY');
var date = moment('{date_compl}', 'DD-MM-YYYY');
var diff = date.diff(dob, 'y');
diff;

In this calculation {birthmonth} and {birthyear} will need to be replaced with your variables name for birth year and birth month. You can also test this calculation in the calculation helper tool.

year variable age calculation

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Calculate the age using a date variable: EDC/CDMS
  • Calculate time difference between two time fields: EDC/CDMS
  • Calculate the difference between two dates: EDC/CDMS
  • Calculate time difference in hh:mm:ss (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