Select to view content in your preferred language

Way to get rid of year value in arcade date expression

83
4
Jump to solution
Tuesday
GeorgeJonesRIGOV
Regular Contributor

Hi all, I'm seeing if it's possible to manipulate a date function so i could use date fields as a range to update the feature each month automatically, and won't have to change the year every time. Here is the code I have so far. 

esriCommQuesiton.png

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When building the date, just insert a variable for the year

var time = Now();
var time3 = Text(Now(), "MMMM DD, YYYY");
var thisYear = Year(Now());

if (time >= Date(thisYear, 7, 1) && time < Date(thisYear, 8, 1)) {
  return $feature["August"];
}

 

View solution in original post

4 Replies
DavidPike
MVP Notable Contributor

Arcade has a Month() function.  It returns 1 (Jan) - 12 (Dec).
Date functions | ArcGIS Arcade | Esri Developer
this article should have all the code you need, incl. a dictionary to map the number to the month name.

How To: Extract Month Names from a Date Field Using ArcGIS Arcade in Map Viewer

 

0 Kudos
GeorgeJonesRIGOV
Regular Contributor

Thanks for the help, but I should have been clearer - I'm looking for a Date function that only takes the month and day, but without the year. 

0 Kudos
KenBuja
MVP Esteemed Contributor

When building the date, just insert a variable for the year

var time = Now();
var time3 = Text(Now(), "MMMM DD, YYYY");
var thisYear = Year(Now());

if (time >= Date(thisYear, 7, 1) && time < Date(thisYear, 8, 1)) {
  return $feature["August"];
}

 

GeorgeJonesRIGOV
Regular Contributor

thank you Ken! That worked!

0 Kudos