Select to view content in your preferred language

Using Arcade to format date for feature?

103
2
Thursday
Labels (1)
BaileyDeSimone
New Contributor

Hello,

I have a feature (Incorporation_Date) that, in ArcGIS pro, I set to format 'Month D, YYYY' like the other date columns in my dataset. There are only two map points with this feature, so I use the following expression:

if (IsEmpty($feature.Incorporation_Date)) {
  return null;
}
  else {"Incorporated on " + ($feature.Incorporation_Date) + " (" + $feature.Incorporation_Citation + ")"}
 
However, the expression returns the date formatted as YYYY-MM-DD 00:00:00. I attempted to add Text(DateOnly before) the feature to remove the time section, but would like to know how to re-format the date to Month D, YYYY.
 
Thank you!
0 Kudos
2 Replies
CodyPatterson
MVP Regular Contributor

Hey @BaileyDeSimone 

From what I'm seeing you're pretty close! Give this a shot here:

if (IsEmpty($feature.Incorporation_Date)) {
  return null;
} else {
  return "Incorporated on " + Text($feature.Incorporation_Date, "MMMM D, YYYY") + " (" + $feature.Incorporation_Citation + ")";
}

This uses the same Text feature, but assigns the format of the MMMM D YYYY, I think MMMM is the right format for this case!

Cody

RPGIS
by MVP Regular Contributor
MVP Regular Contributor

@CodyPatterson has the right method but I am simply putting this one out there to show a simpler way of writing the same code.

// Option A
var D = $feature.Incorporation_Date
iif( !IsEmpty( D ) , "Incorporated on " + Text(D, "MMMM D, YYYY") + " (" + $feature.Incorporation_Citation + ")" , Null )

// Option B
var N = Null
if( !IsEmpty( $feature.Incorporation_Date ) ){ N = "Incorporated on " + Text($feature.Incorporation_Date, "MMMM D, YYYY") + " (" + $feature.Incorporation_Citation + ")" }
return N