1

I'm trying to update each row in my point shapefile with a date. What I want is the first row in my below table to read 7/14/2022 12:00:00 AM, second row to be 7/14/2022 12:01:00 AM, third row to be 7/14/2022 12:02:00 AM, etc. I'm trying to find the correct field calculator expression to accomplish this with. It seems to me that some sort of arcade expression using DateAdd() is most suggested online, but that seems use two separate fields to merge calculate a difference. Does anybody have suggestions on how to update each row of time data in this specific format?

enter image description here

2
  • 1
    Shapefile does not support finer than day resolution in date fields. dBase-III is nearly forty years old, so it's amazing that it was Y2K compliant (and can be used at all)
    – Vince
    Commented Jul 14, 2022 at 21:47
  • I know some may get tired of reading this soapbox but Field Calculator does not guarantee row order, so it should not be used with order-dependent updates on a data (there are some klugey dictionary-based workarounds, but I don't encourage them). You should be using cursors so you can sort the data either in Python or SQL before updating it.
    – bixb0012
    Commented Jul 15, 2022 at 14:24

2 Answers 2

2

First of all as @Vince points out, shapefile format was a poor choice for creating your data in. If you type into the help file "Geoprocessing considerations for shapefile output" you will discover why. So what you want cannot be achieved in a Shapefile; create your data in a File GeoDatabase. I would also add abandon any future work with Shapefiles as the File GeoDatabase is a superior format offering lots of functionality that a Shapefile cannot. You will literally be working faster and smarter with a File Geodatabase!

With that said the Python code to use in a Calculate Field tool could be:

DT = None
def ComputeTime():
    global DT
    if DT is None:
        DT = datetime.datetime(2022,7,14,12,0,0,0)
    DT = DT + datetime.timedelta(minutes=1)
    return DT

The tool being set up as below:

Tool

1
  • 1
    Thank you. This helps me a lot in understanding. I'll definitely keep this in mind in the future. I'll mark as answered. Commented Jul 15, 2022 at 14:44
0

In ArcGIS Pro, you can calculate fields based on previous rows both with field calculator and Python. With the field calculator, try to add these lines in the Code Block and make sure to set "Python" as a parser :

previousDate = None
def DateIncrement(currentDate): 
  global previousDate
  if previousDate is None:
    previousDate = "7/14/2022 12:00:00 AM"
  resultDate = DateAdd(prev, 1, 'minutes')
  previousDate = currentDate
  return resultDate
1
  • Isn't DateAdd a function of an arcade expression? Also, are 'previousDate' and 'resultDate' the field names being used in the expression? Commented Jul 14, 2022 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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