Anu Raj
Anu Raj

Reputation: 39

Need to write a trigger

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

Answers (1)

Hraefn
Hraefn

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

Related Questions