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
  • Calculations with date and time

Extract only date or time from date and time field in 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

Using the extracted date or time

If you want to extract a part of a date and time field (i.e. the date only, or the time only), you can use the following templates. Replace {your_datetime_variable} with your own variable name.

 

To extract a date from a date and time field:

 

var splitted_datetime = '{your_datetime_variable}'.split(';');
if(/^((0?[1-9]|[12][0-9]|3[01])[-](0?[1-9]|1[012])[-](19|20)?[0-9]{2})*$/.test(splitted_datetime[0])){
splitted_datetime[0];
} else {
"Date has not been filled in";
}

 

To extract the time from a date and time field:

 

var splitted_datetime = '{your_datetime_variable}'.split(';');
if(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(splitted_datetime[1])){
splitted_datetime[1];
} else if(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(splitted_datetime[0])){
splitted_datetime[0];
} else {
"Time has not been filled in";
}

Using the extracted date or time

The codes above, first split the field to separate date and time. Then, it extracts only the item [0] (date) or [1] (time).

 

We can use this same process if we want to extract the date or the time to use it in another calculation instead of just showing it separately.

 

For example, we can have two date and time fields, one for the admission of the patient in the hospital and another one for the discharge. If we want to know the amount of complete days spent in the hospital we do not need the time, just the dates. We can then combine the code in the article Calculate the difference between two dates with the one described here as follows:

 

var datetime1 = '{your_datetime_variable1}'.split(';');
var datetime2 = '{your_datetime_variable2}'.split(';');
getDateDiff(datetime2[0],datetime1[0],'d')
time isolate

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Doing date (and time) calculations in EDC/CDMS: the basics
  • Show a message in EDC/CDMS when the date is more than X days before today or in the future
  • Check if a date is before another date and show an error in EDC/CDMS if so
  • Adding hours or minutes to a time field in 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