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

How to compare two Date fields

Hi all,


So I am trying to create a Trigger that will pull the Opportunity Owner's Quota for the month that the Opportunity closes in and then populate a custom field called Owner_Quota__c on the Opportunity.


I have been trying to run a query on the Revenue Forecast object that pulls the Opportunity Owners Quota if the following conditions are met:


RevenueForecast = rf

Opportunity = o


rf.OwnerId = o.OwnerId

// I need to limit the Quota to the month that the Opp closes in

MONTH(rf.StartDate) = MONTH(o.CloseDate)

// I need to limit the Quota to the year that the Opp closes in

YEAR(rf.StarteDate) = YEAR(o.CloseDate)


I would include more code, but I can't even save my trigger because I have so many different ways that I am trying to do this.


Any help would be appreciated since I can't find very much info on the Revenue Forecast object pertaining to triggers.  Let me know if you need to more info.





Shashikant SharmaShashikant Sharma

I am not able to get your issue correctly could you please if ou want to compare two date field values then it can be directly compared like this


Date d =;

Date d1 =;

system.debug('*************** Compare Date :  ' + (d == d1));


It will give you


DEBUG|*************** Compare Date : true in debug logs


You can comepare Date, Month or Year paart separately also using like

d.Month() == d1.Month()


Please let me kow if you want to ask something else.