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
Steve DSteve D 

SOQL WHERE Date > NOW()-x

Hi All,
 
Im hoping someone can help me with an SOQL query:
 
I'm trying to return activities within the last 3 months. I.e where Activity Date >= NOW()-3 months
The SOQL documentation suggests you have to supply a native comparison value ie not a calculation.
 
Has anyone come across this before?
 
Thanks in advance,
 
Steve
 
 
 
Best Answer chosen by Admin (Salesforce Developers) 
NasipuriNasipuri

Hi Steve,

You can use the phase  as below in your query 

WHERE Date = LAST_N_DAYS:90

Think this will solve your problem.
 
Thanks and Regards,
Dinesh Nasipuri
 

All Answers

NasipuriNasipuri

Hi Steve,

You can use the phase  as below in your query 

WHERE Date = LAST_N_DAYS:90

Think this will solve your problem.
 
Thanks and Regards,
Dinesh Nasipuri
 
This was selected as the best answer
jrotensteinjrotenstein
See: Date Formats and Date Literals


Message Edited by jrotenstein on 04-11-2008 11:17 AM
Steve DSteve D
Thanks, perfect!
LBartonLBarton

Are there other expressions that work such as Last_N_Hours?  I want to check if some objects have been modified hourly.

 

NasipuriNasipuri

Hi Barton,

 

Unfortunately this LAST_N_DAYS is not there in the SOQL , but that is not at all the end.

 

You can have a formula number field say Update_Hour and formula as  (NOW() - LastModifiedDate) * 24)

 

and use the Clause like WHETE Update_Hour > 2

 

Thanks and Regards,

Dinesh Nasipuri

Dinesh.Nasipuri@gmail.com

LBartonLBarton

thanks a lot for the advice!

 

 

ellospiderellospider
Dinesh,When you say LAST_N_DAYS not avaialble in SOQL, are there any specifics areas we cannot use this date literal?
Message Edited by ellospider on 01-29-2010 10:19 AM
NasipuriNasipuri

Hi,

 

Sorry that was a Typo error , the LAST_N_DAYS is available with WHERE Clause , there are so such LAST_N_HOUR .

 

Thanks,

Dinesh Nasipuri