0

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.

8
  • 4
    Issues 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-DD – JimT Jul 12 '19 at 22:02
  • 2
    What type of geodatabase is this stored in? What data type is being used to store what look like dates (but could be strings)? – PolyGeo Jul 12 '19 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 Jul 13 '19 at 12:12
  • 1
    can you add a field and then format date w field calculator to ISO standard, then sort, then remove field if needed? – Gary Lester Jul 13 '19 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 Jul 16 '19 at 21:29
0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.