Select to view content in your preferred language

Arcade DateDiff expression

1440
2
Jump to solution
01-27-2022 01:33 PM
BobWheeler
Frequent Contributor

I have inspection dates to symbolize my locations.  I was using the expression below and it works fine, but now I need to add another variable.

IIf(DateDiff(now(), $feature.dateauditperformed, 'years') < 1, "Inspected","2/3 Year")

 

Now I want those locations inspected within the last year = Current, >1 and <=2 years = Second Year, and everything else = Third year.

 

This is what I've been trying to work with.  All I seem to get is "other".

 

var year = DateDiff(Now(), $feature.dateauditperformed,'years');

if (year <= 1) return 'Current';
else if (year > 1 && year <= 2) return 'Second Year';
else return 'Third Year';
end

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Keep in mind that your conditions are evaluated in order, so you don't really need to include the "year > 1" on the second condition.

Also, when writing if statements in Arcade, you need to enclose the following command in brackets. And you don't need to put "end" on there.

var year = DateDiff(Now(), $feature.dateauditperformed,'years');

if (year <= 1){
    return 'Current'
} else if (year <= 2){
    return 'Second Year'
} else {
    return 'Third Year'
}

But really, you could also accomplish this with a When function, too. It's more or less equivalent.

var year = DateDiff(Now(), $feature.dateauditperformed,'years');

return When(year <= 1, 'Current', year <= 2, 'Second Year', 'Third Year');

Try either one of those. Do you still get a response of "other"?

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

Keep in mind that your conditions are evaluated in order, so you don't really need to include the "year > 1" on the second condition.

Also, when writing if statements in Arcade, you need to enclose the following command in brackets. And you don't need to put "end" on there.

var year = DateDiff(Now(), $feature.dateauditperformed,'years');

if (year <= 1){
    return 'Current'
} else if (year <= 2){
    return 'Second Year'
} else {
    return 'Third Year'
}

But really, you could also accomplish this with a When function, too. It's more or less equivalent.

var year = DateDiff(Now(), $feature.dateauditperformed,'years');

return When(year <= 1, 'Current', year <= 2, 'Second Year', 'Third Year');

Try either one of those. Do you still get a response of "other"?

- Josh Carlson
Kendall County GIS
BobWheeler
Frequent Contributor

I utilized the When statement with success.  Thank you very much for your assistance!

0 Kudos