Convert date/time string to date

516
6
10-05-2021 08:50 AM
Labels (1)
by Anonymous User
Not applicable

I'm using a data expression for a pie chart in my dashboard.  I could not get the date selector to work to set an filter action, and realized it's because it's seeing my date/time field (created_date) as a string.  
I found this post from 2018 from @XanderBakker , listing out every month, etc to parse it out.  Is this still necessary or is there a less involved way to get the data part into a date format.  I don't need time, just M/D/Y.

https://community.esri.com/t5/developers-questions/text-to-date-using-arcade-expressions/td-p/523768

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

what does the current string format look like?

Is the data being updated regularly or can you just do a field calculate on the original data, i.e. select the necessary year, month, day parts from the string and then form a Date object from that?

return Date(year, month, day)

if your data keep changing, you're going to have some fun doing this on the data expression side of things, basically taking the featureSet apart then rebuilding it with a new date field.  but we can help you with that i'm sure, although i would say Xander is the guy to go to with these.

0 Kudos
by Anonymous User
Not applicable


This is the format: 5/17/2021 10:44 AM

New records are being added daily, but once they are added, the date does not change.  So it sounds like from your reply then, there is a simpler way than breaking it all part.  I'm newer to Arcade but I'll look at your comment and see if I can figure it out.

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

I don't think so, featureSetByPortalItem() won't respect any on-the-fly arcade expressions you have in something like a web map.  I think unless you alter your source data format to a datetime (and alter the current process to ensure you create one) you will have to rebuild from a feature dictionary.

here's a few examples:

Create effective data expressions—ArcGIS Dashboards | Documentation

 

0 Kudos
by Anonymous User
Not applicable

I'm using the standard editor tracking date field in my hosted layer, so I don't think I have any options on altering the field type.  I'm also a little confused on how it's technically a date field, but yet stored as string??

0 Kudos
EmilyMcLeanACTGOV
Occasional Contributor

There are a few reasons why your date field may be stored as a string. The following article talks about some of the different reasons. 

Work with Date Fields 

Emily
0 Kudos
by Anonymous User
Not applicable

FYI, I went back to this and someone else had the same problem and a response had the fix.  I had to cast my date field as a number, don't know why, but was an easy fix.  
The post that had the fix is here: 

https://community.esri.com/t5/arcgis-dashboards-questions/date-fields-in-data-expressions-for-serial...

0 Kudos