Select to view content in your preferred language

Arcade date function for expression in popup

19150
8
Jump to solution
10-14-2019 01:58 PM
ToddHelt
Occasional Contributor

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

1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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

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

View solution in original post

8 Replies
XanderBakker
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".

0 Kudos
ToddHelt
Occasional Contributor

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

0 Kudos
KenBuja
MVP Esteemed Contributor

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

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

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?

0 Kudos
XanderBakker
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:

0 Kudos
KenBuja
MVP Esteemed Contributor

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

0 Kudos
ZacharyBaron1
Occasional Contributor

Thanks Ken, that is exactly what I needed!

0 Kudos
BugPie
by
Frequent Contributor

Thank you! Sometimes the answer is not a long read through Arcade date documentation. 

0 Kudos