Show a message in EDC/CDMS when the date is more than X days before today or in the future
Table of Contents
If you want to give a message when the date is more than X days before today, or in the future, you can use this formula.
In this example 10 days or more are used as the limit.
You can enter your variable name between these brackets {Variablename}
var castorDate = moment('{Variablename}','DD-MM-YYYY');
var today = moment();
var tenDaysAgo = moment().subtract(10, 'days');
if(castorDate.diff(moment()) > 0 ){
'This date is in the future';
} else {
if(castorDate.diff(tenDaysAgo) > 0) {
'This date is less than 10 days ago';
} else {
'This date is more than 10 days ago.';
}
}
Show a message if a year is in the future
Use this calculation template if you would like to check whether the year is in the future and display a message
var castorYear = moment('{Variablename}').format('YYYY');
var todayYear = moment().format('YYYY');
if(castorYear > todayYear ){
'This year is in the future';
} else {
'This year is correct';
}
Test this template in the calculation helper.
Show a message if years are not the same
Use this calculation template to check if year variables entered are the same and display a message.
var year_1 = moment('{year1}', 'YYYY');
var year_2 = moment('{year2}', 'YYYY');
var diff = year_2.diff(year_1, 'y');
if (diff < 0) {
'Error';
} else {
'OK';
}
Test this template in the calculation helper.