[SalesForce] Difference in minutes between two datetime fields

I need to calculate the difference in minutes between two datetime fields inside a formula.

The following works if the dates are different

(date2__c-date1__c)*24*60

But if its the same date then this fails as the difference between the two values subtracted from each other is zero.

Is there an easy solution to this?

Best Answer

Difference b/w two date time would never be 0 until you have exact date time value. So in your case, you can resolve your issue either by changing the return type of formula field to TEXT or NUMBER(With 0 Decimal Places).

  1. If you changed the return type to TEXT then the formula would be :

    TEXT((date2__c - date1__c)*24*60)
    
  2. If you changed the return type to NUMBER(With 0 Decimal Places) then the formula would be :

    (date2__c - date1__c)*24*60
    

I would prefer to go with the 2nd option.

Related Topic