2

I have a date field called ExprDate and I want to set a definition query to select all records from today's date plus the next 7 days.

This is what I have:

ExprDate >= CURRENT_DATE +7

The expression is returning values, but not for the current date and next 7 days only. Any thoughts?

I am working on a file geodatabase on 10.2.

3

Your current expression is looking for dates that are 7 days or more than the current date.

Try:

ExprDate <= (CURRENT_DATE + 7) AND ExprDate >= CURRENT_DATE

EDIT

As mentioned, the above only works in some database environments. I ran into an issue implementing the above solution for data that was stored in a SQL database. Below is the Definition Query I used to get the last 30 days of data:

DATEDIFF(d, FIXED_DATE , GETDATE()) <= 30 AND NOT FIXED_DATE > GETDATE() 
  • 1
    Note that this will not work on all data sources. In a database you'd need to use a date function supported by that database (and these are very different). – Vince Feb 20 '15 at 18:52
0

As Vince mentioned in his comment, the actual query varies on the database.

For Oracle, it would look something like this:

ExprDate <= trunc(SYSDATE + 7) AND ExprDate >= SYSDATE

Note: this is untested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.