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
cactusdavecactusdave 

How do I get Last 30 Days in a SOQL Statement (Getdate(), Today()???)

I am trying to create a SOQL Statement to get data from the last 30 days

 

For example, I would do this on SQL Server by writing:

Select * from case where createddate > getdate -30

Is there a similar way to keep this in place with SOQL.

 

I have tried GetDate()-30, Today()-30 but no luck.

Best Answer chosen by Admin (Salesforce Developers) 
EIE50EIE50

Hi Dave,

 

Do try this,

 

 

Select * from case where WHERE CreatedDate = LAST_N_DAYS:30

 

Thanks

 

All Answers

EIE50EIE50

Hi Dave,

 

Do try this,

 

 

Select * from case where WHERE CreatedDate = LAST_N_DAYS:30

 

Thanks

 

This was selected as the best answer
cactusdavecactusdave

Thanks. This worked perfectly.