You need to sign in to do that
Don't have an account?

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
Thanks
RD
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
Thanks
RD
Hi,
Please use Today() + 5
Try like below:
Date.Today().addDays(5)
Let me know if it works or not!!!
If it works mark this as a best answer!!!
Thanks,
Raj
Please try below code once.
Thanks
Varaprasad
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.
Thanks
Ankit Maheshwari
I needs to be done in query only. No APEX.
Is it possible to do this SOQL query only?
Thanks
Hi,
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
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
Thanks
Ankit Maheshwari
Use
in Where Clause. Its equivalent to today() + 5 and you dont need any apex too. Everything is done in SOQL.
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
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.
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;
You need to modify your query
Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = Date.today().addDays(5);
OR
Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = NEXT_N_DAYS:5
Go through these links for more info.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi