Select to view content in your preferred language

Arcade Expression Error

125
3
Jump to solution
Friday
AndyIngall
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)
0 Kudos
1 Solution

Accepted Solutions
CodyPatterson
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

View solution in original post

3 Replies
CodyPatterson
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

AndyIngall
New Contributor III

Thanks very much, ideal...

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