Apex provides a native daysBetween instance method on Date (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htmDate instance method), daysBetween()
.
date startDate =
date.newInstance(2008, 1, 1);
date dueDate =
date.newInstance(2008, 1, 30);
integer numberDaysDue =
startDate.daysBetween(dueDate);
In your case it would be
temp_LatestGapLen = temp_PB_CurrSubBeg.daysBetween(temp_PrevSubEnd);