Find your content:

Search form

You are here

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

 
Share

I wanted to have a formula field with difference between a datefield and todays date. The formula field is a number to store the no of days.

The formula that i have is

TODAY() - SDate__c

SDate__c is a Date field.

But when i check syntax it results in

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

What am i doing wrong here? OR

How do i get the date difference between todays date and sdate?


Attribution to: Prady

Possible Suggestion/Solution #1

EDIT :

My bad, it does actually let me create a formula field if both fields are of type date, so TODAY() - Date_Field__c in a Number formula field seems to compile okay. Check that your date field is not actually DateTime ? And that your Formula field is of type number.


I don't believe you can use mathematical operators on date fields.

You will need to write something like

365*(Year(today()) - year(sdate__c)) + 30*(month(today() - month(sdate__c))) + (day(today())- day(sdate__c))

Attribution to: techtrekker

Possible Suggestion/Solution #2

Can you go back and check your field definitions - is sDate__c definitely a date and your formula is definitely a number formula?
Field definitions


I defined a couple of fields and I was able to use the formula as you would expect TODAY() - initial_date__c
enter image description here


Otherwise surely you are in a world of trouble re-inventing the wheel trying to cope with leap years and month lengths?


Attribution to: Doug B
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5034

My Block Status

My Block Content