Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

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

share|improve this answer
    
Thanks for the assist! –  AMM Dec 10 '12 at 19:54
add comment

Apex provides a native Date 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);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.