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
Pooja Singh 21Pooja Singh 21 

Need to find all cases where ClosedDate is more then 18 months.

I find it difficult to subtract two datetime fields as it gives me arithmetic expression error. I want to use this in apex class. Please suggest how to find all case which are closed more than 18 months.
Best Answer chosen by Pooja Singh 21
bob_buzzardbob_buzzard
You can subtract months using the addMonths method to generate a datetime of exactly 18 months ago. Then look for cases with a closeddate less than or equal to that datetime.
 
DateTime latest=System.now().addMonths(-18);

List<Case> cases=[select id from Case where CloseDate<=:latest];

 

All Answers

bob_buzzardbob_buzzard
You can subtract months using the addMonths method to generate a datetime of exactly 18 months ago. Then look for cases with a closeddate less than or equal to that datetime.
 
DateTime latest=System.now().addMonths(-18);

List<Case> cases=[select id from Case where CloseDate<=:latest];

 
This was selected as the best answer
Pooja Singh 21Pooja Singh 21
It works for me. Thank you Bob.
nishad basha 7nishad basha 7

Hi, bob_buzzard
      How to create a high volme customer portal user using visualforce page?

iam getting these type of error how to solve above scenario plase give any ideas.  
         Errors
Contact: Cannot create a portal user without contact
    Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Cannot create a portal user without contact: [ContactId] once i give the details same error will occur in both Accounts