7 Replies Latest reply on Mar 2, 2017 1:21 PM by philmodjunk

# Need assistance with my Elaspsed date/time calculation

Hi All,

I am currently calculating how long a service ticket has been open in days.

Let ( Stop = If ( IsEmpty ( Date_Closed ) ; Get ( CurrentDate ) ; Date_Closed ) ; Ceiling (stop - Date_Created ) )

I now would like to change that to hours.  So would by new calc be:

Let ( Stop = If ( IsEmpty ( Time_Closed ) ; Get ( CurrentTime ) ; Time_Closed ) ; Ceiling (stop - Time_Created ) ) or

Let ( Stop = If ( IsEmpty ( Time_Closed ) ; Get ( CurrentTimestamp ) ; Time_Closed ) ; Ceiling (stop - Time_Created ) )

Thanks

• ###### 1. Re: Need assistance with my Elaspsed date/time calculation

Use the time stamp option for both this calculation and your "closed" and "created" fields if there is any chance that midnight might occur between the two times.

Your calculation produces elapsed time in seconds. To show that as hours, divide by 3600 or choose a result type of "time".

• ###### 2. Re: Need assistance with my Elaspsed date/time calculation

Cool that work just fine.  I elected to go with your first choice.

Now I have another issue.  With a time less than an hour I get a decimal.  In this case I would like for the system to place a zero in my elapsed::timefield instead.

• ###### 3. Re: Need assistance with my Elaspsed date/time calculation

Depending on what you need, you might take a look at the ceiling and round functions, but if you mean exactly what you ask, that you want a zero result only if the amount is less than 1 hour (such as 0.99 hours), you can use an if or case function to return 0 when the result is this small.

• ###### 4. Re: Need assistance with my Elaspsed date/time calculation

Ok, so that works.  But from a metrics point of view that might not be the best choice.  I then changed from hours to minutes which is easer to convert but MGMT might not be in the mood to convert minutes to hours.  Is there a way I can display 1 hour and 36 minutes, elapsed time, to display 1:36 instead of 96 minutes.

• ###### 5. Re: Need assistance with my Elaspsed date/time calculation

See my first response. You can leave off dividing by the number of seconds in an hour and select a Time result type. Now you can use Time data formatting to get a typical HH:MM display of your result.

• ###### 6. Re: Need assistance with my Elaspsed date/time calculation

Thanks that worked.  Hopefully this is my last request.  I went to lunch and when I came back the elapsed time was still the same.  How can I get this calculation to run in real time?

• ###### 7. Re: Need assistance with my Elaspsed date/time calculation

To start, the calculation has to be unstored. But if you want it to continually update every second, even that won't work as it at least requires some even to "refresh" the window.

You may have to go with a scripted approach, possibly using Install OnTimer Script to get something that updates continuously.