I got a task at work that required me to calculate the difference between the date and time fields using Salesforce. To fulfill this requirement, I define an advanced formula.
In this Salesforce Tutorial, we will learn how to calculate DateTime field difference in Salesforce. Additionally, we will review how to use Salesforce Lightning to distinguish between datetime fields.
Calculate DateTime Field Difference in Salesforce
In Salesforce, there are many scenarios where we may need to get the difference between two datetime fields.
For example, we want to calculate the difference between 5-03-2022 9:53 and 6-03-2022 10:58 and want to display the result as: 25 Hours 05 Minutes.
For this, we will find the difference between the day, hours, minutes, and seconds of two datetime values by subtracting one datetime from the other.
But, if we directly subtract the datetime value, we will get the difference of the dates in fractions. To calculate the difference, we need to use some of Salesforce’s built-in functions, such as FLOOR, MOD, ROUND, and TEXT.
Additionally, the difference between two datetime fields in Salesforce returns the result in Both Number