HOW TO
In Map Viewer for ArcGIS Online and ArcGIS Enterprise, extracting month names from a date field and populating a string field with these names is crucial for enhancing data analysis and visualization. This process is useful for categorizing and filtering data based on specific months, facilitating temporal analysis and trend identification.
This article provides the workflow for extracting month names from a date field named 'Date_Joined' and populating them in a new string field named 'Ext_Month' using an Arcade expression in Map Viewer.
Note: Skip to Step 3 if the script is being run on an existing field.
var date = $feature.<field_name>;
if (!IsEmpty(date)) { var monthNumber = Text(Month(date) + 1, '00');
var months = { "January": "01", "February": "02", "March": "03", "April": "04", "May": "05", "June": "06", "July": "07", "August": "08", "September": "09", "October": "10", "November": "11", "December": "12" };
for (var key in months) { if (months[key] == monthNumber) { return key; } } return "Invalid month number"; } else { return "Date not available"; }
Below is the full working code of the Arcade expression.
var date = $feature.Date_joined; if (!IsEmpty(date)) { var monthNumber = Text(Month(date) + 1, '00'); var months = { "January": "01", "February": "02", "March": "03", "April": "04", "May": "05", "June": "06", "July": "07", "August": "08", "September": "09", "October": "10", "November": "11", "December": "12" }; for (var key in months) { if (months[key] == monthNumber) { return key; } } return "Invalid month number"; } else { return "Date not available"; }
The image below shows the month extracted from the date field, which is then populated as text in the newly created string field.
Get help from ArcGIS experts
Download the Esri Support App