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
srilakshmib87srilakshmib87 

Filer the records retreived by created Date

Hi,

 

I want to query and retreive records from one object whose created dateis  less than  3 days from current date.

Since createdDate field is a standard field of data type datetime.I am trying to filter it out by giving the following in the where condition but i m getting query error.

 

CreatedDate.date< =today-3;

 

 

Can anyone please help me in this.

 

 

Thanks,

Srilakshmi B

SurekaSureka

Hi,

 

You can use like the below - "CreatedDate <=: Date.Today() -3".

 

Hope this helps.

 

Thanks

srilakshmib87srilakshmib87

Hi,

 

Thanks for your reply but even I faced error with that approach.So, finally i was able to acheive by following code.

 

 

datetime dt=  datetime.now();
Date d =dt.Date()-3;

 

and in the where condition of the query i gave CreatedDate >=:d and CreatedDate < =today to retreive the records created in last three days.

 

Thanks,

Srilakshmi B

Pradeep_NavatarPradeep_Navatar

you can use this SOQL Query to retreive your records :

 

integer i = [select count()  from account where CreatedDate <=: system.now()-10 T00:00:00+00:00];

 

Refer this link http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm

for more information.

 

Hope this helps.