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
Eric_SalesForceEric_SalesForce 

Date Functions in SOQL

Hi I have a SQL query that I want to setup through SalesForce, it querys where someDate >= (date manipulation to get last monday to last sunday).

I want to query the same way on salesforce and im not sure how I can win the existsing Date Functions available. 

I wanted to use LAST_WEEK but that gets me sunday - saturday which isn't what I wanted, I was hoping do something like:

where someDate >= LAST_WEEK + 1 AND where someDate >= LAST_WEEK + 6

Is this possible? 

thanks
Best Answer chosen by Eric_SalesForce
OyeCodeOyeCode
Use the methods here to startofthe week, which will give you sunday and then subract - 2 from there through adddays(-2), read more on methods here 


http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_instance_methods.htm

All Answers

Vinit_KumarVinit_Kumar
You can use addDays() method of salesforce.Try something like below :-

date d = system.today().addDays(+1); // It will add 1 day to current day.
Account [] acc=  [select id from account where createdDate = :d];

To know more about this metod.Please refer below link :-

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_addDays.htm
Eric_SalesForceEric_SalesForce
I probably should have been more specific. I am trying to run a crystal report pulling from the salesforce database which I am able to do however I need to do this inline so I can't create objects to store parts of the data. I tried running system.today() and it doesn't like the syntax there. 
OyeCodeOyeCode
Here is the code I developed for you 

Apex Controller : 

//Author - Harshit Pandey
//Blog - http://www.oyecode.com
public class dateHandler{
    public Date theDay { get { return Date.today().toStartofWeek().addDays(-2); }}
    //class to handle the dates
    public dateHandler()
    {
       
    }
}



Visualforce Page Code : 

<apex:page showHeader="false" sidebar="false" controller="dateHandler">
<apex:iframe src="http://www.oyecode.com" scrolling="true" id="theIframe"/>
   <apex:outputText value="{!theDay}" />
</apex:page>

OyeCodeOyeCode
Use the methods here to startofthe week, which will give you sunday and then subract - 2 from there through adddays(-2), read more on methods here 


http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_instance_methods.htm

This was selected as the best answer