Hello
I am trying to create a scriptool to select the survey data after a certain start date
If Annual_Growth is 10 I want it to add 20 days to the Initial_Date to give the start date
If Annual_Growth is 20 I want it to add 50 days to the Initial_Date to give the start date
Survey_Data = arcpy.GetParameterAsText(0)
Annual_Growth = arcpy.GetParameterAsText(1)
Initial_Date = arcpy.GetParameterAsText(2) #Date input (date format is dd/mm/yyyy)
T_date = datetime.datetime(Inital_Date)
start_date = T_date + datetime.timedelta(days = num_days)
if Annual_Growth ==10: num_days = 20
elif Annual_Growth == 20: num_days = 50
Where_Clause = "DateTimeUTC >= '{}'".format(start_date)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)
The first issue I run into is that the initial date input is perhaps in the wrong format for timedelta to add the days ?? Any help would be appreciated. Thank you
Solved! Go to Solution.
Thanks for reply Tom. Yep thats where I started also. Got there in the end. In a roundabout way.
Survey_Data = arcpy.GetParameterAsText(0)
Date_last_treatment = arcpy.GetParameterAsText(1)
AGrowth = arcpy.GetParameterAsText(2)
Initial_date=datetime.datetime.strptime(Date_last_treatment,'%d/%m/%Y')
Growth = int(AGrowth)
if Growth == 10:
Ndays = 10
elif Growth == 20:
Ndays = 20
N_date = Intial_date + datetime.timedelta(days = Ndays)
Start_date= datetime.datetime.strftime(N_date, '%d/%m/%Y')
Start_date1 = "timestamp'{}'".format(Start_date)
Where_Clause = "DateTimeUTC >= {}".format(Start_date1)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)
A couple things come to mind…
Thanks for reply Tom. Yep thats where I started also. Got there in the end. In a roundabout way.
Survey_Data = arcpy.GetParameterAsText(0)
Date_last_treatment = arcpy.GetParameterAsText(1)
AGrowth = arcpy.GetParameterAsText(2)
Initial_date=datetime.datetime.strptime(Date_last_treatment,'%d/%m/%Y')
Growth = int(AGrowth)
if Growth == 10:
Ndays = 10
elif Growth == 20:
Ndays = 20
N_date = Intial_date + datetime.timedelta(days = Ndays)
Start_date= datetime.datetime.strftime(N_date, '%d/%m/%Y')
Start_date1 = "timestamp'{}'".format(Start_date)
Where_Clause = "DateTimeUTC >= {}".format(Start_date1)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)