+ Start a Discussion

Add 5 days to today date in SOQL query

Hi All,

I want to add 5 days to today's date.
Example : Suppose i have a date field Collection_date__c which is having a date of 24th may 2017 and I am quering it today(19th May 2017). It should display this 24th Mau record.

Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = today + 5;

Please Help

Deepak Maheshwari 7Deepak Maheshwari 7


Please use Today() + 5

Maharajan CMaharajan C

Try like below:


Let me know if it works or not!!!

If it works mark this as a best answer!!!

Nithesh NNithesh N
Hi, I believe this one works for you. 
SELECT Id, Collection_date__c FROM Custom_Object__c Where Collection_date__c = NEXT_N_DAYS:5
You can check more date Literals at this Link https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

v varaprasadv varaprasad
Hi ,

Please try below code once.
Date Dat5 = date.today().adddays(5);

list<contact> lstCons = [select id,name,Birthdate from contact where 
                        Birthdate =: Dat5];

Ankit Maheshwari 2Ankit Maheshwari 2

Could you please use the below code snipt

Date dVar=System.Today()+5;
Select Id, Collection_date__c from Custom_Object__c where Collection_date__c =: dVar;

I used this and it is working properly. If it will not work so please let me know.

Ankit Maheshwari
Hi Ankit,

I needs to be done in query only. No APEX.
Is it possible to do this SOQL query only?

Ankit Maheshwari 2Ankit Maheshwari 2


I am so sorry but in query we can not use this. we need to store date in a variable first then we can use it in query.

you can check the below link for the same. Our concern is about 5 days so here is only the way which i shared with you, rest all you can check on the below link

Ankit Maheshwari

Nithesh NNithesh N

WHERE Collection_date__c = NEXT_N_DAYS:5

in Where Clause. Its equivalent to today() + 5 and you dont need any apex too. Everything is done in SOQL.
v varaprasadv varaprasad
SOQL to get next 7 days records
Next_N_Days is used to get next N days records from the object.

The below query will fetch accounts where it's Next Billing Date is today and within next 7 days.

Sample SOQL:

SELECT Id FROM Account WHERE Next_Billing_Date__c >= TODAY AND Next_Billing_Date__c  <= Next_N_Days:7
Kyle NovelliKyle Novelli
Hey RD,

I had a similar problem and found the solution that worked for me.

Sample SOQL query, given your case:
Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = NEXT_N_DAYS:5 AND Collection_date__c > NEXT_N_DAYS:4

I know this thread is pretty old, but hopefully this helps others down the road. 
Priyananth RPriyananth R
Salesforce provided a date literal NEXT_N_DAYS:n you want set query as dynamically. try this 
n is integer,starts 00:00:00 of the current day and continues for the next n days

Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = NEXT_N_DAYS:5;