I want to be able to select by attributes for dates that change weekly. I have gotten an invalid expression error for the follow script where the date needs to change to the current date and the same date just the following year every time I run it. I want to be able to create a model with multiple versions of this script.

import arcpy
in_layer = arcpy.GetParameterAsText(0)
in_field = arcpy.GetParameterAsText(1)
one_date = arcpy.GetParameterAsText(2)
two_date = arcpy.GetParameterAsText(3)

new_selection = "NEW_SELECTION"
where_clause = "in_field >= date 'one_date 00:00:00' AND in_field <= date 'two_date 00:00:00'"

arcpy.SelectLayerByAttribute_management(in_layer, new_selection, where_clause)

You're using strings when you want to be using the variable.


where_clause = "in_field >= date '{} 00:00:00' AND in_field <= date '{} 00:00:00'".format (one_date, two_date)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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