Inline Date Variables in Model Builder

3322
3
03-21-2011 07:20 AM
PhilHolleran
Occasional Contributor
I am attempting to use two date variables as sql query parameters in the select features tool.  My data is stored in an Access personal geodatabase and dates are in #mm-dd-yy hh:mm:ss# format.

I have defined two date variables in model builder, FromDate and ToDate, and have defined them as model parameters.  I am looking to select from features WHERE: %FromDate% <= [DateField]<= %ToDate%.

The only problem is that no matter what syntax I try I end up with either a data type mismatch error and/or no records returned.

I have tried:
- "%FromDate% <= [DateField] <= %ToDate%"
- "#%FromDate%# <= [DateField] <= #%ToDate%#"
- "#&'%FromDate%'&# <= [DateField] <= #&'%ToDate%'&#"
and other combinations to no avail.

I can successfully select records when actual '#dd:mm:yy#' are passed, just not variable values.

Can anyone provide some insight on how to pass Access-friendly inline date variables through a sql query?

Thanks
- Phil H
0 Kudos
3 Replies
AdamBeard
New Contributor II
Try this.

[DATEFIELD] >= #%From Date%# AND [DATEFIELD] <= #%To Date%#
0 Kudos
CarlosIsaac_Cabrera
Occasional Contributor II
I am having an issue with select by attributes not accepting > date '%my variable%' the variable is set in the model but it continues to give errors.  If I replace my variable with a date it works fine.  Please help.
0 Kudos
PaulLohr
Occasional Contributor III
I am trying to use a date variable in a RecordSet. I have imported a schema that has a date column. The date variable is not accepted within the column it belongs in (within RecordSet). The column within RecordSet will only take an actual date - not a variable that is of type Date.
0 Kudos