HOW TO

Extract names of the month from a date field using ArcGIS Arcade in Map Viewer

First Published: October 1, 2024
Last Published: May 14, 2026

Summary

In Map Viewer for ArcGIS Online and ArcGIS Enterprise, extracting the names of the month from a date field and populating a string field with these names enhances data analysis and visualization. This process is useful in categorizing and filtering data on a month basis, facilitating temporal analysis and trend identification.

This article provides the workflow to extract the names of the month from a date field, 'Date_joined', and populating them in a new string field, 'Ext_Month', using Arcade in Map Viewer.

Procedure

  1. In Map Viewer, click the hosted feature layer. On the item page, click the Data tab.
Note:
Skip to Step 3 if the script is being run on an existing field.
  1. In the Table view, create a new field with the String data type. Refer to ArcGIS Online: Add a field or Portal for ArcGIS: Add a field for instructions. In this example, the field 'Ext_Month' is created.
  2. Click the field header and select Calculate.
  3. For Select language, click Arcade. Click Next.
  4. In the Arcade expression dialog box, specify the following expressions to extract the names of the month from a date field:
    1. Define the date field. Replace <field_name> with the name of the date field. In this example, 'Date_joined' is used.
var date = $feature.<field_name>;
  1. Check for the availability of the date and extract the month number from the date.
if (!IsEmpty(date)) {

    var monthNumber = Text(Month(date) + 1, '00'); 
  1. Define an object for the months with corresponding two-digit values.
    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"
    };
  1. Iterate through the months object to find the corresponding month name.
    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";  
}
  1. Click Run to verify the expression, and click Run calculation to apply the query.
The Arcade expression dialog box with the Arcade expression to extract month names from the date field

The table shows the month extracted from the date field, which is then populated as text in the newly created string field.

The table displaying the extracted months from the date field in a string field

Article ID: 000033574

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options