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
CokeCoke 

Formula to net the greater of two dates (Last Modified and Last Activity)

I want to create a field to reflect the last time an Opportunity was changed (by modificication or an activity). I wrote the following formula and used a return type of date:

 

IF( LastModifiedDate  >  LastActivityDate,  LastModifiedDate, LastActivityDate )

 

But I am getting this error message and I can't figure out how to work around it. Any help would be much appreciated.

 

Error: Incorrect parameter for function >(). Expected DateTime, received Date

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

You're comparing 2 different Datatypes in your fomula, that's what you're getting the error.  

 

LastModified is Date/Time field

LastActivity is a Date field

 

you need to use the

IF(DATEVALUE(LastModifiedDate) > LastActivityDate,

DATEVALUE(LastModifiedDate),

LastActivityDate )

 

function to extract the Date value from the LastModifiedDate field. 

 

 

So you probably want a formula that looks like

 

 

All Answers

WYamWYam

You're mis-matching two fields.

 

I believe Last modified is by default a date/time while the the other may be date. Either that or the field you're trying to indicate the changes on is defined as date and you're trying to write a date/time.

Steve :-/Steve :-/

You're comparing 2 different Datatypes in your fomula, that's what you're getting the error.  

 

LastModified is Date/Time field

LastActivity is a Date field

 

you need to use the

IF(DATEVALUE(LastModifiedDate) > LastActivityDate,

DATEVALUE(LastModifiedDate),

LastActivityDate )

 

function to extract the Date value from the LastModifiedDate field. 

 

 

So you probably want a formula that looks like

 

 

This was selected as the best answer
CokeCoke
Steve- Thank you very much! Using "DateValue" was the information I needed.
CokeCoke

Steve helped me with this formula for a custom field a few weeks ago but I found a small problem with it and I'm hoping he or someone else can help. Basically it is only returning a value if both a "Last Activity" and "Last Modified Date" exist. If no activity exists then it is just blank. Here is the formula again:

 

 IF(DATEVALUE(LastModifiedDate) > LastActivityDate, DATEVALUE(LastModifiedDate), LastActivityDate )

 

Any help you can provide would much, much appreciated.

 

Thanks

Steve :-/Steve :-/

What value do you want the Formula to return if the Last Activity = NULL?  

 

An IF statement has to have an Else result. 

Steve :-/Steve :-/

Okay, try flipping the formula around like this (Last Modified Date is never blank):

 

 

IF(LastActivityDate > DATEVALUE(LastModifiedDate),

LastActivityDate,

DATEVALUE(LastModifiedDate))

 

 
Message Edited by Stevemo on 03-18-2010 02:49 PM
CokeCoke
Bingo! That was it. Thanks Steve!
Steve :-/Steve :-/
No problem...  you just owe me one of these> http://beeradvocate.com/beer/profile/863/7971
CokeCoke
Next time I'm in Boston I will definitely look you up and take you out for a beer.
Steve :-/Steve :-/
wait'll you get my Bar Tab...