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.

Parents Reply
  • Hi Joseph Moore,

    You haven't specified what version of Sugar you are on but in version 7.6.x there is a function for hoursUntil. This works the same as daysUntil where you simply wrap it around the date you check.

    So to get a simple number of hours between you can "subtract(hoursUntil($date1),hoursUntil($date2))". This will give you your required number of hours difference.

    If you require this to be split into hours and minutes then there are two viable options that I can see.

    1) Create a second calculated field that formats the one we just discussed for hours only. This allows you to have a human readable field on the views and a pure hours field to be able to report on (I would suggest not having the format field reportable).

    2) Have to field customised by code development either by yourself or by getting a quote from your Sugar partner  (if they cannot perform this then contact SugarCRM). This would allow you to have option 1 as just 1 field, meaning it stores the hours in the database and just formats the data when viewing the records. To my knowledge this should then give you the readability and reporting as the reports use database queries.

    I hope this helps, and sorry for not screens hots but I done this on my phone.

Children