function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ArtemiyArtemiy 

Comparing Dates

I would like to select all objects (e.g. opportunities or other)  with CloseDate within next 7 days. I am trying to use the following code:

Code:
date MyDate = system.today().adddays(7);

Opportunity[] opps = [select name from Opportunity where CloseDate < MyDate];

 but I am getting "Compile Error: unexpected token: MyDate at line..."

What expression should I use for my query?

jf317820jf317820
i believe you can use "NEXT_N_DAYS:7"

as in, [SELECT Id FROM Opportunity WHERE CloseDate = NEXT_N_DAYS:7]