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
Arun BArun B 

SOQL : Date - n days

Hello there,
I have a requirement where I need to write a where clause which needs to set the date value to '<Date>'-10 days .

For e.g: I want to query something like this:

Select Sample_Object__r.Ship_Date__c,Sample_Object__r.Transaction_Number__c,c.Quantity__c,c.Lot_Number__c from  

spl_sample_object_items__c c where   Sample_Object__r.Ship_Date__c>= 2008-04-01 - (10) and Sample_Object__r.Ship_Date__c <= 2008-10-18 + (10)

Any function available in SOQL or do I need to write a logic for this on the client side . Any hints would be truly appreciated !


Thanks,
Arun B
TehNrdTehNrd
Where are those dates coming from? It seems strange they are hardcoded.

You can add and days to dates using Date methods. I haven't tried it but I'm guess you can just add negative days to subtract.

See page 139:

http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf
Arun BArun B
Thanks for the respons TehNrd. I use flex as the client, so I cannot use this Apex date method. The dates are hardcoded because it is just a runtime query.

Pls let me know if you have any idea on how to do this in Flex if we cannot do this stuff in SOQL directly.


Thanks,
Arun B

TehNrdTehNrd
Unfortunately I'm not to familiar with Flex but I know that SOQL will not like this syntax:

Sample_Object__r.Ship_Date__c>= 2008-04-01 - (10)

I think you will need to subtract 10 days from the date in Flex before you pass it to the SOQL call.


Message Edited by TehNrd on 06-11-2008 11:06 AM