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.
2 Comments
Thank you, keep them coming
ReplyDeleteThank you, keep learning..!
DeletePost a Comment