Wednesday 16 March 2016

Extension to salesforce standard formula for calculating the date difference in Minute and Seconds

Hello Awesome Salesforce Developers ,

Few days ago, I got a requirement to calculate the elapsed time between Case open date and Case closed date.

There is standard formula of salesforce which will calculate the Date Difference (Field with datatype formula and return type text)









The above formula will calculate the difference in days, hours and minutes.

My requirement is to extend this formula to calculate the difference in days, hours, minutes and seconds.

Let's calculate it !!! 

First will understand some factors about datetime.
1 Day = 24 Hours
24 Hours = 1440 Minutes
1440 Minutes = 86400 Seconds

Create a field with datatype formula and return type as Text. Use the below formula and you are set !!!!

FLOOR() -  Used to round up to nearest integer.
ROUND() - Returns the nearest number to a number you specify. 


Cheers !!!!

12 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. without asking you just gave solution for issue at perfect time...it helped me a lot

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Im sorry got confused...I was calculating for the difference between today date and created date ....thanks

    ReplyDelete
    Replies
    1. Hi Sangeetha.. Comment above you is yours or not ?

      Delete
    2. Hi Ajay i have the above comment which is not appropriate ...I have a query while calculating the difference between a date and now in terms of days hours minutes and seconds ...Is der any possibility that the formula field gets refreshed for seconds and minutes automatically in the record detail page (like we use rerender in visualforce)

      Delete
    3. Hi Sangeetha.
      If we change any of date1 or date2 then formula will automatically refreshed else I don't think it will refreshed. You can check the consideration for formula field.

      Delete