How to calculate duration between two date/time fields?

I have two date/time fields (both will always be in the past) from which I need to calculate a duration. (i.e. the difference between one and the other.) Ideally, I could display it as hours:minutes, but I'll settle for just hours if I have to.

I tried this:

abs(subtract(number($time_out_c),number($time_in_c)))

but it yields nothing. (a blank field)

I'm a complete new to using calculated fields. Any help would be appreciated.

  • Hi Joseph,

    Have you tried something like this, (where 86400 is the number of seconds in a day):

    round(divide(subtract(number(timestamp($date_modified)), number(timestamp($date_entered))),86400),0)

    Which gives you the number of days between 2 dates.  But of course the formula could be modified

    in ways to produce the proper format you are looking for.

    Bob Bers

  • Hello All,

    We have used following calculation as a whole for minutes

    "multiply(subtract(multiply(subtract(divide(subtract(number(timestamp($chat_endtime1_c)),number(timestamp($chat_starttime1_c))),86400),floor(divide(subtract(number(timestamp($chat_endtime1_c)),number(timestamp($chat_starttime1_c))),86400))),24),floor(multiply(subtract(divide(subtract(number(timestamp($chat_endtime1_c)),number(timestamp($chat_starttime1_c))),86400),floor(divide(subtract(number(timestamp($chat_endtime1_c)),number(timestamp($chat_starttime1_c))),86400))),24))),60)"

    From this link: SugarCRM, Inc.