Check if a date is before another date and show an error in EDC/CDMS if so
1. Create a calculation field after two date fields. You can choose the variable names yourself, but you will have to change them in the calculation template in step 2. In our example, we will check if the Visit 1 (variable date2) date is before the Screening Visit date (variable date1)
2. Use this formula for the calculation field:
//Is date 1 before the date 2?
var dateDiff = getDateDiff('{date1}','{date2}', 'day');
if(dateDiff < 0 ){
"No";
} else {
"Yes";
}
Please note, that date1 should be the older date. If you have chosen other variable names, then you have to replace date1 and date2 with your own variable names. Check this template in the calculation helper here.
3. Set the calculation field up like this.
4. Define a message for the calculation field.
5. The end result when you enter data for a record.
The calculation template:
var dateDiff = getDateDiff('{date1}','{date2}', 'day');
if(dateDiff < 0 ){
"No";
} else {
"Yes";
}