I am trying to set up a tool to query based on a date range and secondary field
I have created three Variables that i have set up as Parameters, Start Date, End Date, Customer_Code.
I have the customer code selecting correctly however i get an error when i include my date range.
(Date >= '%Start Date%' AND Date <='%End Date%') AND Customer_Code = '%Customer Code%'
This is the error i get
NEW_SELECTION "Customer_Code = '35' AND Date => '3/1/2016 3:33:02 PM'"
Start Time: Wed Mar 30 16:06:22 2016
ERROR 000358: Invalid expression
An invalid SQL statement was used.
An invalid SQL statement was used. [Customers_3_24_16]
An invalid SQL statement was used. [SELECT OBJECTID FROM Customers_3_24_16 WHERE Customer_Code = '35' AND Date => '3/1/2016 3:33:02 PM']
Failed to execute (Select Layer By Attribute).
Failed at Wed Mar 30 16:06:22 2016 (Elapsed Time: 0.00 seconds)
I think the issue is that when i apply a definition query my date values look as like this
Date = date '2016-03-01 00:10:00'
Thanks in advance for your help!
Dates are tough to work with, i suggest you use select by attribute to see the format the date query is looking for.
I have my SQL expression going connected to a select by attributes i think the issue is the "Date = date '2016-03-01 00:10:00'"
not sure if this is an issue but i have underlined and made bold the part that might be stopping it from working
Date = date '2016-03-01 00: 00:00'
Check your error message I'm not sure you can use PM in the date field try using a date from a select by attribute Get Unique Values test
Date => '3/1/2016 3:33:02 PM'
The biggest problem is that date-time formats are often format and database-specific. It looks in the help like Wes is correct that PM is not likely to work for most data sources.
The format you reference is correct for file geodatabase:
Datefield = date 'yyyy-mm-dd hh:mm:ss'