Can you cast data from string field type to date for use in dashboard date selector

04-19-2021 11:53 AM
Labels (3)
New Contributor II

Can you use Arcade to change a field type from Text to Date on the fly for use with a dashboard date selector? I see how it can be done in a pop up, but that doesn't interact with the date selector.


It looks like a data expression would work. Are there any examples similar to my use case?


Thank you,

0 Kudos
3 Replies
MVP Frequent Contributor

yeh I'd definitely say a data expression.  Syntax would be exactly the same as the popup, except that you would reference the feature first by something like:

 (abridged example from Data Functions | ArcGIS for Developers)

var portal = Portal('');
var features = FeatureSetByPortalItem(portal, '7b1fb95ab77f40bf8aa09c8b59045449')

I can't really offer you an example of the date string to datetime/Esri date without knowing what the string looks like, but here are some example methods Date Functions | ArcGIS for Developers.

MVP Esteemed Contributor

Unfortunately, you can't get Arcade to work like that in the dashboard. A date selector is "layer agnostic", so to speak, and can't work with non-attribute data, as it is essentially just submitting an SQL query to the feature service.

If you watch the network traffic on your browser, you can see it happen:


Picking that option sends this to request (relevant part bolded):

"orderByFields":"sale_year ASC",
"where":"(sale_date>timestamp '2006-01-02 05:59:59' AND valid_sale=0) AND (sale_date BETWEEN timestamp '2020-01-01 06:00:00' AND timestamp '2021-01-01 05:59:59')"


The only way to get a date filter to work would be to create a true date field. You wouldn't be the first person to create a new field for the sake of a dashboard!

Does the text field consistently contain date values? And is there a reason to maintain it as a text field instead of just converting it?

- Josh Carlson
Kendall County GIS
MVP Frequent Contributor

On looking at the question again, it's not going to be easy, but theoretically you could iterate through the original values and create a text representation of the JSON to create a new feature set with all the existing and new date values - but it's far from trivial.