+ Start a Discussion
Supriyo Ghosh 9Supriyo Ghosh 9 

Apex Trigger Date Range


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 
but this is not working.Please help.
Best Answer chosen by Supriyo Ghosh 9
SandhyaSandhya (Salesforce Developers) 

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,