Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to calculate a duration from two dates dynamically in an Interactive Grid?

Christian Pitet.Jun 22 2026 — edited Jun 22 2026

Hi,

Under APEX 24.1 I have an interactive grid. I want to calculate the fureations (in hours) between 2 dates in the IG. I was inspired by this post from @dasshini-ravi :

https://forums.oracle.com/ords/apexds/post/trying-to-calculate-dynamically-the-sum-of-a-colum-in-an-in-7064

I have done this:

(function($) {
 function update(model) {
     var salKey = model.getFieldKey("DUREE");
     console.log(">> starting sum DUREE column")
     model.forEach(function(record, index, id) {
         var sal = parseFloat(record[salKey]), 
             meta = model.getRecordMetadata(id);
         if (!isNaN(sal) && !meta.deleted && !meta.agg) {
             DUREE = HEURE_FIN - HEURE_DEBUT;
         }
     });
 }
 $(function() {
     $("#EMP").on("interactivegridviewmodelcreate", function(event, ui) {
         var sid,
             model = ui.model;
         if ( ui.viewId === "grid" ) {
             sid = model.subscribe( {
                 onChange: function(type, change) {
                     console.log(">> model changed ", type, change);
                     if ( type === "set" ) {
                          if (change.field === "HEURE_DEBUT" ) {
                             update( model );
                         }
                     } else if (type !== "move" && type !== "metaChange") {
                       update( model );
                     }
                 },
             } );
              update( model );           
             model.fetchAll(function() {});
         }
     });
 });
})(apex.jQuery);

The calculation is made by substracting HEURE_FIN from HEURE_DEBUT: DUREE = HEURE_FIN - HEURE_DEBUT; and stotinh this value in the field DUREE of the IG grid.

It is not working, could you help me find why?

Best regards.

Comments
Post Details
Added on Jun 22 2026
14 comments
338 views