durationBetween program rule function (feature request)

Hello everyone,

I would like to ask if it would be possible to get a function that calculates the duration between two dates in terms of hours, minutes and seconds.

Start date & time: 2022-02-17T10:00:00
End date & time: 2022-02-18T11:00:00

The function should be like this…

d2:durationBetween(#{start_date_time}, #{end_date_time})

For the above example, this function should return a value of 25:00:00 which is 25 hours, zero minutes and zero seconds.

This would help in turnaround times calculations which is very important for a laboratory.

Thank you

1 Like

Hi @Nelson_Gahima,

Thank you for sharing this idea! Have you tried to experiment if it might be possible to use several of these functions to get the results?

I thought about it but when I started formulating, I realized one would need to understand how these values are calculated so for example (daysBetween(#start_date)*24)[hours] : (minutesBetween(#startDate) : (minutesBetween(#start_date)*60)[seconds]… but I’m not sure this will calculate the actual duration.

If you really need to get these results then I think you can use postgresql SQL scripts to make these calculations.

Please feel free to create a Jira feature request on jira.dhis2.org

I’m tagging @Jim_Grace for input.

Thanks! :pray:

We don’t want ‘totalTimeinHours’:‘totalTimeinMinutes’:‘totalTimeinSeconds’ … and if that’s the result that we’re getting then that’s not what we are looking for! (:


Thank you for a good tip but the issue is that the daysBetween function rounds up or down the number of days, and this won’t calculate the exact duration between two dates.

I have created a Jira feature request and hopefully someone will work on it. Thank you

1 Like

Thank you! I added CoP to the labels and added a comment to this topic page. I also tagged @Jim_Grace there too! (Jira feature request issue: Log in - DHIS 2 JIRA)


1 Like

Much appreciated!

1 Like

@Nelson_Gahima Thank you for the ticket at DHIS2-12680. I’ve left a comment there with some questions.


@Jim_Grace Thank you. I have left a comment in jira with answers.