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
donodono 

Comparing two custom date fields

I am trying to create a report where I have 2 custom date fields.   I want to be able to compare the fields so is field X is greater then field Y it should show it.  Any ideas?
Best Answer chosen by Admin (Salesforce Developers) 
MarkSilberMarkSilber
You will need to create a new formula field that displays the greater of the 2 date fields. Something like the formula below should work.

IF(MyDateFieldx__c > MyDateFieldy__c, MyDateFieldx__c, MyDateFieldy__c)

 

In basic terms, the formula compares the 2 dates and if MyDateFieldx is greater than MyDateFieldy, display MyDateFieldx else display MyDateFieldy. The formula above doesn't take into consideration null dates, but that logic can be added pretty easily.

All Answers

MarkSilberMarkSilber
You will need to create a new formula field that displays the greater of the 2 date fields. Something like the formula below should work.

IF(MyDateFieldx__c > MyDateFieldy__c, MyDateFieldx__c, MyDateFieldy__c)

 

In basic terms, the formula compares the 2 dates and if MyDateFieldx is greater than MyDateFieldy, display MyDateFieldx else display MyDateFieldy. The formula above doesn't take into consideration null dates, but that logic can be added pretty easily.
This was selected as the best answer
amish.jainamish.jain

I am using this formula

(TODAY() - Date_Mktg_Lead__c) - IF((LastActivityDate - Date_Mktg_Lead__c)> (Action_Taken_Date__c - Date_Mktg_Lead__c), (LastActivityDate - Date_Mktg_Lead__c), (Action_Taken_Date__c - Date_Mktg_Lead__c))

 

This Includes three date fields 

 

Date_Mktg_Lead__c

LastActivityDate

Action_Taken_Date__c 


This is working well if all the date fields are filled but if one of the field is blank it dosn't work. Please suggest....

Will SaffenWill Saffen
@MarkSilber You mentioned that if the nate is NULL then that logic could be added pretty easily, how would you add that logic?