Hello friends, In this post you will find a formula that helps you to get difference between two datetime fields in salesforce. So let's get started,
Get difference between two datetime fields in salesforce
Here I am posted two formula that shows the difference between datetime fields.
1) Difference in hours and minutes.
IF(
FLOOR((EndDate__c-StartDate__c)*24)>9,
TEXT(FLOOR((EndDate__c-StartDate__c)*24)),
"0" & TEXT(FLOOR((EndDate__c-StartDate__c)*24))
)
&"."&
IF(
ROUND(MOD((EndDate__c-StartDate__c)*1440,60),0)>9,
TEXT(ROUND(MOD((EndDate__c-StartDate__c)*1440,60),0)),
"0"&TEXT(ROUND(MOD((EndDate__c-StartDate__c)*1440,60),0))
)
Output:
2) Difference in day, hours, minutes and seconds.
IF (FLOOR((EndDate__c- StartDate__c)) > 0, TEXT(FLOOR((EndDate__c- StartDate__c)) ) & " Days ", "")
& IF(FLOOR(MOD((EndDate__c- StartDate__c)* 24, 24 )) > 0, TEXT(FLOOR(MOD((EndDate__c- StartDate__c)* 24, 24 ))) & " Hours ","")
& TEXT(ROUND(MOD((EndDate__c- StartDate__c)* 24 * 60, 60 ), 0)) & " Minutes "
& TEXT(ROUND(MOD((EndDate__c- StartDate__c)* 24 * 60*60, 60 ), 0)) & " Seconds"
Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
3 Comments
Thank you, keep them coming
ReplyDeleteThank you, keep learning..!
DeleteVery helpful post! Calculating the difference between two Date, Time fields in Salesforce is a common requirement, especially for tracking response times, task durations, or service level agreements. Your explanation makes it easy to understand how to use formulas or Apex to get precise time differences. It's also important to consider time zone settings and daylight-saving adjustments, which can affect accuracy. For businesses planning to migrate data from Salesforce to Zoho CRM, understanding how Date Time fields are handled in both platforms is essential to ensure data consistency. Thanks for sharing this practical and informative guide!
ReplyDeletePost a Comment