Getting the Time of Category Change
AnsweredI have a Category Field called Status, which has three options: Open, Inprogress and Closed. I was wondering if I could get the Time of when the Category Field is selected as closed. The reason behind this is I want to Calculate the time between the Item being Created and Closed. e.g. Ticket was created at 14:07 and the ticket was closed at 17:23 (@ticketClosed  @ticketCreated). The time take is: 3 Hours 16 Minutes. I was wondering if this was possible using a calculation field and if not if there is another way around it.

Hi Ben,
this should work:
var closeTime = moment(); var createdTime = moment(@Created On); var timeDiff = (closeTime.diff(createdTime,'minutes')/60).toFixed(2); @Status == 'Closed' ? timeDiff : 0;
If createdTime = 14:07 and closeTime = 17:27 you'll get the result = 3.33 hours (= 3 h 20 m). The result is a number so you can use this value for further calculations). "toFixed(2)" sets the decimals .
If you don't need the value for further calculations, try:
var closeTime = moment(); var createdTime = moment(@Created On); var timeDiff = closeTime  createdTime; moment(timeDiff).format("hh [Hours] mm [Minutes]")
result = 03 Hours 20 Minutes (but the value is a text string and it's not so easy to do further calculations with it)
Rainer
rg@delosconsulting.com 
Try this one. If days, hours or minutes = 0, it doesn't show this unit.
var closeTime = moment(); var createdTime = moment(@Created On); var timeDiff = closeTime  createdTime; var dCount = moment.duration(timeDiff).days(); var hCount = moment.duration(timeDiff).hours(); var mCount = moment.duration(timeDiff).minutes(); var dText = dCount > 0 ? dCount + " Days " : ""; var hText = hCount > 0 ? hCount + " Hours " : ""; var mText = mCount > 0 ? mCount + " Minutes" : "" var result = dText + hText + mText @status == "Closed" ? result : ""
Rainer
rg@delosconsulting.com
Please sign in to leave a comment.
Comments
4 comments