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
Sharad Jain 9Sharad Jain 9 

How Can I find date 365 days before from a given date in a field using soql query

I have a date field in Account . I need to find the date 365 days before the mentioned date in SOQL query
Raj VakatiRaj Vakati
Try like this 
DateTime currentTime = System.now();
        DateTime cutOff = currentTime.addDays(-365);
        return Database.getQueryLocator([SELECT Id, StatusFROM Case WHERE 
                                         CreatedDate <= :cutOff ]);

 
Niraj Kr SinghNiraj Kr Singh
Hi Sharad,
I am considering a Date type field "TestDate__c" on Account object. Find the logic for the same here:

Date backDate = System.Today().addDays(-365);   //you can use System.Today().addYears(-1);
List<Account> accountList = [SELECT Id, Name, TestDate__c FROM Account WHERE TestDate__c <=: backDate];


//Note You need to change Date field "TestDate__c" accordingly

Hope it will help you.
Thanks
Niraj