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
kris chitkris chit 

Retrun values between 175th -185th days back from today in SOQL

Hi,

There is a field called "Display_LastModifiedDate" on Orders. I am trying to retrieve orders with "Display_LastModifiedDate" between 175th -185th days back from today dynamically. I cannot hardcode 175th and 185th dates because if I query it after a week the 175th and 185th dates change. Please guide me.

Thanks
Best Answer chosen by kris chit
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Kris,

You can do something like below .
 
Date d1 = Syatem.today.addDays(-175 );

Date d2 = Syatem.today.addDays(-185 );

Your query will look like below .

Select id from Order where Display_LastModifiedDate >= :d1 and  Display_LastModifiedDate >= :d2

Please mark it as BEST ANSWER if it helps you .

All Answers

Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Kris,

You can do something like below .
 
Date d1 = Syatem.today.addDays(-175 );

Date d2 = Syatem.today.addDays(-185 );

Your query will look like below .

Select id from Order where Display_LastModifiedDate >= :d1 and  Display_LastModifiedDate >= :d2

Please mark it as BEST ANSWER if it helps you .
This was selected as the best answer
kris chitkris chit
Hi Ashish,

Thanks for the reply. Shouldn't it be Select id from Order where Display_LastModifiedDate >= :d1 and  Display_LastModifiedDate <= :d2
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Kris,

This is same query i have written above .
kris chitkris chit
The second condition in your query should be the other way around. It should be Display_LastModifiedDate <= :d2. Please correct me if I am wrong ? The results should be in between 175 and 185.
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
I think, my query is correct , you can try changing the condition it in your code .