# How to get total elapse time in hour and minutes.

**URL:** <https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102>\
**Category:** Classic Servoy\
**Created:** [June 25, 2012, 8:49pm UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102 "2012-06-25T20:49:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hardina09](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hardina09](https://forum.servoy.com/u/hardina09)\
**Post date:** [June 25, 2012, 8:49pm UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/1 "2012-06-25T20:49:26Z")

</div>

I am working with dates can anyone know how to get difference of two event.timestamp(). In my form I am having Start button and Stop button. I want time elapse between two event.getTimeStamp() in format of HH:MM. How can I get the hours and minutes.

Any suggestions is appreciated.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [June 25, 2012, 10:40pm UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/2 "2012-06-25T22:40:19Z")

</div>

Hi,

You could simply get the difference between the 2 dates in milliseconds and calculate the hours and minutes from that like so:

```auto
/**
 * @param {Date} eventStart
 * @param {Date} eventStop
 * @returns {String}
 */
function getElapsedTime(eventStart, eventStop) {
    // Get the milliseconds between the 2 events and calculate the hours and minutes
    var _nDiff = eventStop - eventStart,
        _nHours = Math.floor(_nDiff / 1000 / 60 / 60),
        _nMinutes = Math.floor((_nDiff - (_nHours * 60 * 60 * 1000)) / 1000 / 60);
    return _nHours + ":" + _nMinutes;
}

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [June 26, 2012, 8:48am UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/3 "2012-06-26T08:48:19Z")

</div>

That’s quite an event if you measure it in hours and minutes instead of milliseconds! Looks like you could use some performance optimization ![:lol:]( "Laughing")

---

<div class="post-metadata">

**Author:** ![Mark\_Crichton](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Mark\_Crichton](https://forum.servoy.com/u/Mark_Crichton)\
**Post date:** [June 26, 2012, 9:49am UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/4 "2012-06-26T09:49:52Z")

</div>

This works for me. I have it as a function in my database so any change to the two fields automatically updates the elapsed field.  
Uses Dateutils plugin

function TimeTaken()  
{

// Create an “empty” duration and set its fields later  
var vDuration = plugins.DateUtils.Duration();  
vDuration.days = 22;  
vDuration.hours = 9;  
vDuration.minutes = 12;  
vDuration.seconds = 8;

var vlinstart = plugins.DateUtils.DateTime(linstart);  
var vlinstop = plugins.DateUtils.DateTime(linstop);  
vDuration = plugins.DateUtils.Duration(vlinstart,vlinstop);

return vDuration.hours + vDuration.minutes / 60  
}  
Regards  
Mark

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [June 26, 2012, 10:42am UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/5 "2012-06-26T10:42:25Z")

</div>

I actually prefer Roberts implementation because it doesn’t return decimals and it doesn’t rely on the optional dateUtils plugin (newcomers might not know it is not included with Servoy, feature request?).

---

<div class="post-metadata">

**Author:** ![hardina09](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hardina09](https://forum.servoy.com/u/hardina09)\
**Post date:** [June 26, 2012, 5:33pm UTC](https://forum.servoy.com/t/how-to-get-total-elapse-time-in-hour-and-minutes/16102/6 "2012-06-26T17:33:29Z")

</div>

Thank you all for detail discussion
