chocolatte

Using DATEADD function to previous row in field calculator

Discussion created by chocolatte on Feb 4, 2013
Latest reply on Feb 5, 2013 by chocolatte
Hi, I have a feature class with several thousand points each with a start and end date/time field. A few of the points (stations) already have a designated start and end date/time. There are points between each station that need to have date/time values spaced a certain number of seconds apart based on the start time in the previous record (see attached). I've tried using the field calculator on the "start" field in both ArcGIS 9.3.1 and 10 using different variations of expressions I found on the web. Results have yielded the 1st date/time being repeated in subsequent records, increments of the year in serial format, or general errors.

Again I've tried different approaches, but below is a general idea of what I've been working off of in ArcGIS 9.3.1.

Static lastValue as variant
Dim Output as DATE
Dim pStartValue as DATE
Dim i as Long

pStartValue = #10/13/2012 4:28:23 PM#
i=2

If lastValue=pStartValue Then             [also tried "if IsNull(lastValue)", "if IsEmpty(lastValue)"]
Output = DATEADD("s",i,pStartValue)   [also tried "output=pStartValue"]
Else
Output = DATEADD("s",i,pStartValue)
End If
i=i+2                                               [also tried without incrementing the i value]
lastValue = Output

__esri_field_calculator_splitter__
Output

I will eventually be adding some seconds to the start field and putting the result in the end field, but that expression is pretty straightforward with the DATEADD() function. I've used an increment script before, but can't seem to adapt it to date/time values. Any help is appreciated. I don't look forward to copy/pasting/editing the date/time values for thousands of records and don't want to mess with the fields via MS Access.

Thanks, Charlotte

Attachments

Outcomes