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
Supriyo Ghosh 9Supriyo Ghosh 9 

Apex Trigger Date Range

Hi,

I am using one trigger which will calculate a date range from my Policy object to Opportunity Object.
I am having a field named Proposal Date in Opportunity and Maturity date in policy object.
So I want to put a logic like if proposal date is 12/3/2019 so the Maturity date should be 19/3/2019 to 30/3/2019.If this range will true then it will okay otherwise it will through a error.
I have written something like 
 if(io1.Proposal_Date__c<po.Maturity_Date__c-7)
but this is not working.Please help.
Best Answer chosen by Supriyo Ghosh 9
SandhyaSandhya (Salesforce Developers) 
Hi,

Try with below code.

if(!(po.Maturity_Date__c >= io1.Proposal_Date__c+7) && (po.Maturity_Date__c  <= io1.Proposal_Date__c+18));


Usually to test between two date range you will use below syntax.
 
System.Debug(myDate >= startDate && myDate <= endDate);

Best Regards,
Sandhya