Model builder date variable

1929
2
Jump to solution
05-26-2017 10:23 AM
JoseSanchez
Occasional Contributor III

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?

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

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)

View solution in original post

2 Replies
curtvprice
MVP Esteemed Contributor

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)

JoseSanchez
Occasional Contributor III

Your format works thank you!

CRTDATE >=  date  '%DateFrom%'  and CRTDATE  <= date  '%DateTo%'

0 Kudos