[SalesForce] Formula to calculate the difference between two date/time fields in hours:minute format (values in 12-hour clock format)

What is a formula to calculate the difference between two date/time fields in hours:minute (both date/time values in 12-hour clock format)?

Best Answer

The examples which are mentioned in the documentation contains the following:

Finding the Elapsed Time Between Date/Times

To find the difference between two Date values, subtract one from the other like so: date_1 — date_2 to return the difference in days.

Finding the elapsed time between two Date/Time values is slightly more complex. For simplicity, the custom field Diff_c refers to the difference between two Date/Time values. Since Diff_c is a number, you can use this formula to convert it to days, hours, and minutes.

IF(
  Diff_c > 0 ,
  TEXT( FLOOR( Diff_c ) ) & " days "
  & TEXT( FLOOR( MOD( Diff_c * 24, 24 ) ) ) & " hours "
  & TEXT( ROUND( MOD( Diff_c * 24 * 60, 60 ), 0 ) ) & " minutes",
  ""
)