Arcade date function for expression in popup

1109
7
Jump to solution
10-14-2019 01:58 PM
Highlighted
New Contributor III

I am trying to use the Arcade "date" function in an expression for a popup to return the day, month, year but without the time. Well actually would like to lose the day of the week too. The documentation I refer to the time as an "optional" field:

IIf(IsEmpty($feature.InspDt), Date($feature.PrevInspDt), Date($feature.InspDt))

Returns this...

"Thu Mar 21 2019 20:00:00 GMT-0400 (Eastern Daylight Time)"

So our archived time data is all mucked up and for our purposes we only really need month, day, year anyway. Is there something I can add to this Arcade Date function so that it returns the date but without the "20:00:00 GMT-0400 (Eastern Daylight Time)", and ideally without the day of the week "Thu" portion as well??


Thank you!

arcgis online arcade‌

arcade attribute expressions‌

#arcade pop-ups

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Honored Contributor

Have you tried using the Text function to format the date?

Text($feature.PrevInspDt, 'MMMM D, Y')‍‍‍‍‍‍‍‍‍

View solution in original post

7 Replies
Highlighted
Esri Esteemed Contributor

Hi Todd Helt ,

You could use something like this (assuming that the input date is a string and you want to return a string):

var InspDt = "Thu Mar 21 2019 20:00:00 GMT-0400 (Eastern Daylight Time)";
var arr = Split(InspDt, ' ', 4, 0);
return arr[1] + " " + arr[2] +", " + arr[3];

It will return "Mar 21, 2019".

Reply
0 Kudos
Highlighted
New Contributor III

Xander,

Thanks for your response, starting to see the light lol. I should have clarified the input date is actually not a string, but rather a date type, and I want to return a string like your snippet. Is there a slight modification you can recommend or it a whole other approach?

Thanks again!
Todd

Reply
0 Kudos
Highlighted
MVP Honored Contributor

Have you tried using the Text function to format the date?

Text($feature.PrevInspDt, 'MMMM D, Y')‍‍‍‍‍‍‍‍‍

View solution in original post

Highlighted
New Contributor III

Thanks Ken, I had not thought of that...but just tried that and worked in my IIf function, and it worked as desired so good to go!

// Write a script to return a string of the day, month, year from a date field, to show in the pop-up.
// If the InpsDt is null, then display PrevInspDt, otherwise display InspDt
IIf(IsEmpty($feature.InspDt), Text($feature.PrevInspDt, 'MMM D, Y'), Text($feature.InspDt, 'MMM D, Y'))

I think I am getting a little confused about Arcade for labeling and Arcade for expressions in pop-ups.

Would it be correct to say that certain Arcade functions work for popups but don't work in labeling, and vice versa?

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Hi Todd Helt ,

There are different profiles that define what is possible in Arcade (symbology, labels, pop-up, field calculations, different types of attribute rules and so on). If you go to the playground you can select a profile (where you want to use Arcade) and see what is possible:  ArcGIS Arcade | ArcGIS for Developers 

These are the different profiles you will see:

Reply
0 Kudos
Highlighted
MVP Honored Contributor

Don't forget to click Mark Correct on the reply that best answered your question.

Reply
0 Kudos
Highlighted
New Contributor III

Thanks Ken, that is exactly what I needed!

Reply
0 Kudos