Syntax to calculate the number of hours between 2 events

Hi, Community
In the “Program indicator” module, is there a syntax to calculate the number of hours between 2 events? knowing that these 2 events are of type “Date and time”.

How about this example below?

(d2:daysBetween(#{eventDate1}, #{eventDate2}) * 24) +
((d2:minutesBetween(#{eventDate1}, #{eventDate2}) % 1440) / 60)

Lets break it down

  1. d2:daysBetween(#{eventDate1}, #{eventDate2}): Calculates the number of days between the two dates.
  2. * 24: Converts days into hours.
  3. d2:minutesBetween(#{eventDate1}, #{eventDate2}) % 1440) / 60: Calculates the remaining minutes between the two dates and converts it into hours. The % 1440 ensures you get the remaining minutes after accounting for full days (since 1 day = 1440 minutes).

Try it and see if it will work


hi, @moses_mwale
Thank you for the suggestion. While this solution provides an approximation, it has limitations. It calculates the number of hours in increments of 24 hours, 48 hours, etc., and doesn’t give the exact number of hours if the time difference is less than a full day or includes partial days. This means it doesn’t account precisely for the hours and minutes between the two dates.

In the Accidental exposure to blood (AEB) program, the treating physician must consider the exact elapsed time between the hour of exposure and the start of chemoprophylaxis, which must not exceed a maximum of 72 hours. Otherwise, the chemoprophylaxis will be ineffective.