I'm using ArcMap 10.3. When I use the Identify tool, I often have many results and would like to sort those results in the Identify window. If I right-click on the layer name or features in Identify results, I can "Sort Ascending." This would accomplish the goal in most cases...but I have set the display field for this layer to use a date field, and I would like to sort the results by date values chronologically. When I sort ascending, it sorts the date values by month, like so:
- 1/1/2019
- 2/1/2014
- 3/1/2016
- etc.
But this is not actually chronological.
Any ideas?
The data I'm using is a very large feature class stored on my organization's network, which I am not able to edit.
-
4Issues such as this are why ISO standards are born. I can't help with your direct problem however if the ISO date format is used then the sorting is automatically chronological: YYYY-MM-DDJimT– JimT2019年07月12日 22:02:26 +00:00Commented Jul 12, 2019 at 22:02
-
2What type of geodatabase is this stored in? What data type is being used to store what look like dates (but could be strings)?PolyGeo– PolyGeo ♦2019年07月12日 22:30:56 +00:00Commented Jul 12, 2019 at 22:30
-
I've been able to replicate the issue, looks like the sort function ignores the fact it is date field and treats is as text field so you get a non-chronological order. I suspect there is no solution to this?Hornbydd– Hornbydd2019年07月13日 12:12:46 +00:00Commented Jul 13, 2019 at 12:12
-
1can you add a field and then format date w field calculator to ISO standard, then sort, then remove field if needed?Gary Lester– Gary Lester2019年07月13日 13:45:53 +00:00Commented Jul 13, 2019 at 13:45
-
1@MattLeonard would the db manager create a table view for you and recast the date as something that can be sorted? I think this can be done in the select statement.Gary Lester– Gary Lester2019年07月16日 21:29:10 +00:00Commented Jul 16, 2019 at 21:29
1 Answer 1
I still haven't seen an answer elsewhere, so...I figured out how to use VBScript to parse the date field in the layer's display expression, so that what shows up when you identify features will be a string representing the date that is actually chronological when sorted.
In the display expression, check advanced, and use something like this:
Function FindLabel ([UPDATEDATE])
yr = DatePart("yyyy",[UPDATEDATE])
mon = DatePart("m",[UPDATEDATE])
if Len(mon)<2 then
mon = "0" & mon
end if
dy = DatePart("d",[UPDATEDATE])
if Len(dy)<2 then
dy = "0" & dy
end if
hr = DatePart("h",[UPDATEDATE])
if Len(hr)<2 then
hr = "0" & hr
end if
min = DatePart("n",[UPDATEDATE])
if Len(min)<2 then
min = "0" & min
end if
sec = DatePart("s",[UPDATEDATE])
if Len(sec)<2 then
sec = "0" & sec
end if
FindLabel = yr & "-" & mon & "-" & dy & " " & hr & ":" & min & ":" & sec
End Function
This uses DatePart()
to parse out the year, month, day, hour, minute, and second elements (in my case, from a field called UPDATEDATE), defines them as separate variables yr
mon
dy
hr
min
and sec
, and then constructs a string to constitute the display expression with hyphens and colons in between. To make each element sort correctly, the code uses Len()
to get the length of each element, and if the length is <2, it concatenates "0" in front of the value, so 12 won't be sorted before 3, for example.
Maybe there's a simpler way, but this accomplished what I wanted.
Explore related questions
See similar questions with these tags.