I'm using ModelBuilder to extract a layer by field values.
I'm working on this field :
I tried this method from Extracting by Attribute Using ModelBuilder with User Input? and it worked for many fields but when i try it on a DATE field i got this error.
ERROR 000358: Invalid expression
Failed to execute (Select Layer By Attribute)
Here is my ModelBuilder :
Here is the script used in Calculate Value
import arcpy
def buildWhereClauseMultiValue(table, field, values):
"""Takes a semicolon-delimited list of values and constructs a SQL WHERE
clause to select those values within a given field and table."""
# Add DBMS-specific field delimiters
fieldDelimited = arcpy.AddFieldDelimiters(arcpy.Describe(table).path, field)
# Split multivalue at semicolons and strip quotes
valueList = [value[1:-1] if (value.startswith("'") and value.endswith("'")) else value for value in values.split(';')]
# Determine field type
fieldType = arcpy.ListFields(table, field)[0].type
# Add single-quotes for string field values
if str(fieldType) == 'String':
valueList = ["'%s'" % value for value in valueList]
# Format WHERE clause in the form of an IN statement
whereClause = "%s IN(%s)" % (fieldDelimited, ', '.join(valueList))
return whereClause `
And finaly here's what i wrote in the model as date
I really want to know if the problem is from the script used in Calculate Value or from my Date Expression or from Select Layer By Attribute knowing that Selection Type is NEW_SELECTION ??




whereClauseto the console? It looks like it would be a SQL syntax error, just like the error message states. – Vince May 11 '18 at 12:03Collect Values"model only tool" to see what your Calculate_Value tool yields. – fatih_dur May 11 '18 at 15:04