Getting the Time of Category Change

Answered

Comments

4 comments

  • Rainer Grabowski (FVM)

    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@delos-consulting.com

    0
    Comment actions Permalink
  • Ben Hughes

    Using the Second Method it always starts the time from 12:00. How can I amend it to start from 0:00. Also is there a way to add day's to it after the time take has passed the 24:00 mark?

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    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@delos-consulting.com

    0
    Comment actions Permalink
  • Yacine Ghalim

    what if he wanted to calculate the time between In-progress and Closed?

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk