BLOG
|
Thank you Dan for doing all this extra investigative work!
... View more
02-14-2016
03:12 PM
|
1
|
0
|
296
|
POST
|
PS I just tried it without import datetime and it still works (which makes sense )
... View more
02-10-2016
03:43 PM
|
0
|
0
|
1759
|
POST
|
OK thanks Dan! Below is what worked. (It didnt work if I parsed the ET function into nowww before the def block though). Expression: Reclass(!ActivityDate!) import datetime def Reclass(DateFld): ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(DateFld)).days if (ET < 28): return 1 elif (ET >= 28 and ET < 91): return 2 elif (ET >= 91 and ET < 182): return 3 elif (ET >= 182 and ET < 365): return 4 elif (ET >= 365): return 5
... View more
02-10-2016
03:41 PM
|
0
|
1
|
1759
|
POST
|
Unfortunately the import datetime does not work - I'm still getting the same error. just to re-iterate, I am using arcGIS 10.3 desktop and am using the Calculate Field tool. The code now looks like this (but doesn't work): import datetime ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days def Reclass(ET): if (ET < 28): return 1 elif (ET >= 28 and ET < 91): return 2 elif (ET >= 91 and ET < 182): return 3 elif (ET >= 182 and ET < 365): return 4 elif (ET >= 365): return 5 !ActivityDate! content does contain valid date values and the code string (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days works fine on its own, just wont work when I use it in this context.
... View more
02-10-2016
03:09 PM
|
0
|
4
|
1759
|
POST
|
The error says Error 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1). I dont import the datetime module in Field Calculator. The code for calculating the difference between today and and the collection day as an integer value works fine in Field calculator but its not happy when you try to create a variable using the same code.
... View more
02-09-2016
10:55 PM
|
0
|
7
|
1759
|
POST
|
Hi all, I am using ArcGIS 10.3 to update a field with a numeric value that represents the elapsed time since the data was captured. I can do this in a python script that I have attached to a model but I also want to be able to sometimes do it quickly from within ArcGIS desktop and I am stumped. I have written a 3 step process: 1. Create an integer field then calculate the number of days since today (field name = ET): In Field Calculator, ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days 2. Create a conditional Statement for "Elapsed Time" field as follows: Expression: Reclass(!ET!) def Reclass(ET): if ( ET < 28): return 1 elif ( ET>= 28 and ET < 91): return 2 elif ( ET >= 91 and ET < 182): return 3 elif ( ET >= 182 and ET < 365): return 4 elif (ET >= 365): return 5 3. Delete the ET field I really just want to declare a variable in my conditional statement for ET which would save having to create then delete the ET field, but everything I have tried does not work, for example: Expression: Reclass(ET) ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days def Reclass(ET): if ( ET < 28): return 1 etc etc I cannot find any examples of conditional statements that use a variable instead of a field value in the Field Calculator, so any help would be appreciated.
... View more
02-09-2016
10:25 PM
|
0
|
11
|
7222
|
Title | Kudos | Posted |
---|---|---|
1 | 02-14-2016 03:12 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|