Reputation: 39
I need to write a trigger on Event object. condition : if the difference between 2 fields (both are date time fields) is more than 7days then the trigger should fire and update else not.
eg: the field 1. start data, 2. end date
start date = 06/05/2012 end date = 13/05/2012
then the trigger should fire. can anybody please tell me how to compare date in Apex-code.
Thanks Anu
Upvotes: 0
Views: 602
Reputation: 485
You can use daysBetween().
date startDate = date.newInstance(2008, 1, 1);
date dueDate = date.newInstance(2008, 1, 30);
integer numberDaysDue = startDate.daysBetween(dueDate);
Upvotes: 2