Hi all,
I'm sort of new to coding in general, but I have started trying to use some arcade expressions in my web maps, currently I have a web map which has a date painted field for hydrants and with the arcade expression below I am using the current date and this field to provide a count of the years and days since a hydrant was last painted.
However, I was QC'ing the data and noticed that for hydrants painted after 2020, it is going to be a day short as 2020 was a leap year - if the web map persists beyond 2024, it will then start being 2 days short.
With my limited knowledge I believe that I need to use some type of when or if statement to be able to use 366 rather than 365 (in var d calculation) i'm just now sure how I would go about doing it - would anybody be able to provide some pointers?
Many thanks!
var timeNow = Now();
var survey = $feature["DATE_PAINTED"];
var years = DateDiff(timeNow, survey, 'Years');
// 2.1116274159012844
var y = Floor(years, 0);
var d = (years - y) * 365;
if (IsEmpty($feature.DATE_PAINTED)){
return "-"
} else if (y >= 2) {
return "Last Painted: " + Round(y, 0) + " years and " + round(d , 0) + " days ago."
} else if (y == 1) {
return "Last Painted: " + Round(y, 0) + " year and " + round(d , 0) + " days ago."
} else if (y == 0) {
return "Last Painted: " + round(d , 0) + " days ago."
}