ArcGIS Pro Field Calculator – Update Rows with Incremented Time

arcpycursordatefield-calculatortime

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

Best Answer

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

Related Question