1

This question already has an answer here:

Currently I am trying to use the field calculator to generate the most recent date values out of four fields into one field. I attempted to use the max function to calculate the most recent dates but the calculator doesn't seem to be reading the values as dates. For an example, if I have a date that reads 12/9/2016 and one that reads 7/20/2017, the field calculator chooses the first date because it reads the 9 (in the 12/9/2016 date) over the 20 (in the 7/20/2017 date) as the max. The case seems to be that the field calculator doesn't read the values as dates.

Any possible python codes for the codeblock to solve this issue? I'm thinking the datetime function is necessary in this case?

marked as duplicate by Midavalo Jul 14 '17 at 19:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are all of the fields with dates defined as Date fields or text fields? What format is the source file .shp, FGDB, GDB, etc – Chris M Jul 14 '17 at 19:30
  • @ChrisM All fields are Date type fields. The format of the layer being used is a feature class of a GDB. – Ed102089 Jul 14 '17 at 19:34
  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. This question has been asked already and has an answer. Please see the previous Q&A linked above. – Midavalo Jul 14 '17 at 19:39
  • @Midavalo I attempted the 'dtmax' code you suggested in the other post regarding using the max function to generate the most recent date into the new field. It failed to process the calculation. – Ed102089 Jul 14 '17 at 20:55
  • 1
    @Ed102089 What did it do? Any errors? How are your dates formatted in your field? All the code is doing is forcing the field calculator to see the values as actual dates (as you say in your question that the field calculator isn't doing that by default) and then using the max function same as you were trying. So if it doesn't work it's possibly due to your date format not matching the one in the code. – Midavalo Jul 14 '17 at 20:59