Select to view content in your preferred language

232
3
3 weeks ago
New Contributor III

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??

Tags (3)
1 Solution

Accepted Solutions
Regular Contributor

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

3 Replies
Regular Contributor

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

New Contributor III

Thanks very much, ideal...

by
MVP Esteemed Contributor

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')}```````