Hello everyone,
How to add a date variable in an expression?
I am working with a FGDB in ArcGIS 10.2
I have two variables in Model Builder script:
- DateFrom populated with 5/1/2017 1:03:07 PM
- DateTo populated with 5/31/2017 1:03:23 PM
an the expression I tried with MakeFeature:
CRTDATE >= %DateFrom% and \nCRTDATE <= %DateTo% => fails
CRTDATE >= #%DateFrom%# and \nCRTDATE <= #%DateTo%# => fails
ERROR 000230: Failed selecting with CRTDATE >= #5/1/2017 1:03:07 PM# and \nCRTDATE <= #5/31/2017 1:03:23 PM#
An invalid SQL statement was used.
Any suggestion?
Solved! Go to Solution.
I would avoid the embedded newline in the expression. The syntax is data source dependent, for file geodatabase try:
CRTDATE >= date '%DateFrom%' AND CRTDATE <= date '%DateTo%'
I got the syntax from the help. I have this one bookmarked!
SQL reference for query expressions used in ArcGIS—Help | ArcGIS Desktop (dates and times)
I would avoid the embedded newline in the expression. The syntax is data source dependent, for file geodatabase try:
CRTDATE >= date '%DateFrom%' AND CRTDATE <= date '%DateTo%'
I got the syntax from the help. I have this one bookmarked!
SQL reference for query expressions used in ArcGIS—Help | ArcGIS Desktop (dates and times)
Your format works thank you!
CRTDATE >= date '%DateFrom%' and CRTDATE <= date '%DateTo%'