I have the following Arcade expression to calculate the difference between two dates
var DateRec = $feature.DATEAPRECV
var DateVal =$feature.DATEAPVAL
var ValDays = DateDiff(DateVal, DateRec, 'Days');
return ValDays + " day";
What i have tried to do is add in an IF clause to change the day to days if ValDays => 2 but get errors regard parenthesis
var DateRec = $feature.DATEAPRECV
var DateVal =$feature.DATEAPVAL
var ValDays = DateDiff(DateVal, DateRec, 'Days');
if (ValDays = 1)
return ValDays + " day";
else if (ValDays => 2)
return ValDays + " days";
The error is
Invalid expression.
Error on line 4.
Close parenthesis expected
Can anyone please explain what is wrong??
Solved! Go to Solution.
Hey @AndyIngall
It seems that your comparison operator is in the wrong order and you may be attempting to make an assignment instead of a comparison in your if statement, you would also need to include curly brackets as this is required to encapsulate any return statement, this is what I ended up getting to work here:
var DateRec = $feature.DATEAPRECV;
var DateVal = $feature.DATEAPVAL;
var ValDays = DateDiff(DateVal, DateRec, 'Days');
if (ValDays == 1) {
return ValDays + " day";
} else if (ValDays >= 2) {
return ValDays + " days";
}
Hope that helps!
Cody
Hey @AndyIngall
It seems that your comparison operator is in the wrong order and you may be attempting to make an assignment instead of a comparison in your if statement, you would also need to include curly brackets as this is required to encapsulate any return statement, this is what I ended up getting to work here:
var DateRec = $feature.DATEAPRECV;
var DateVal = $feature.DATEAPVAL;
var ValDays = DateDiff(DateVal, DateRec, 'Days');
if (ValDays == 1) {
return ValDays + " day";
} else if (ValDays >= 2) {
return ValDays + " days";
}
Hope that helps!
Cody
Thanks very much, ideal...
You could also use this syntax
var DateRec = $feature.DATEAPRECV;
var DateVal = $feature.DATEAPVAL;
var ValDays = DateDiff(DateVal, DateRec, 'Days');
return `${ValDays } ${iif(Abs(ValDays) == 1, 'day', 'days')}`