[SalesForce] Date Calculation in Apex

I am lost on how to Calculate the difference between two dates (days):

temp_LatestGapLen = temp_PB_CurrSubBeg - temp_PrevSubEnd;

Left variable is defined as Integer, the other two are Dates. Error received is:

Error: Compile Error: Date arithmetic expressions must 
use Integer or Long arguments at line 449 column 53 

Help? I can't find a reliable reference to this online in my searches despite how simple this seems. Is it implying you can only do date vs integer calculations, not date vs date??

Thanks so much.

Best Answer

Use daysBetween

date startDate = date.newInstance(2008, 1, 1);
date dueDate = date.newInstance(2008, 1, 30);
integer numberDaysDue = startDate.daysBetween(dueDate);

Here ist the doc: Date Methods