function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Delzner5Delzner5 

New to date formulas- Subtracting 2 custom field

I am trying to do a simple subtraction formula for calculating a duration date using

 

Project_End_Date__c - Project_Start_Date__c

 

I get the following error:

Error: Formula result is data type (Number), incompatible with expected data type (Date).

 

What am I doing wrong?

Best Answer chosen by Admin (Salesforce Developers) 
MohandaasMohandaas

Delzner, It works If you set the return type of formula to Number. The output will be the no.of days between two dates.

All Answers

Steve :-/Steve :-/

What is the datatype of your formula field?  If you add or subtract a Date value from another Date value your result is gonna be a number (the number of days).  If you add or subtract a number value from another Date value your result is gonna be a Date (Date +/- the number of days).  

 

Date - Date = Number

Date - Number = Date 

 

You need to create a NEW custom field and specify Formula as the datatype and Number as the result.  Then put your Date1 -Date2 formula in there

MohandaasMohandaas

Delzner, It works If you set the return type of formula to Number. The output will be the no.of days between two dates.

This was selected as the best answer
Shashikant SharmaShashikant Sharma

Your formula retun type should be nubmer as the difference between two dates will give you a Integer Number.

Delzner5Delzner5

thank you all