calculate date duration in js

Hi All,

I need to calculate the duration between two SM datetime fields using javascript and return back the result in SM datetime format. Is this possible?

I know it's perfectly possible using simple RAD coding, but I need this to be in js since it can be called using jscall from any other place.
  • Verified Answer

    Ok, I don't know if this will work for you, but this has worked for me.

    It's a simple JavaScript function that allows you to send two dates/times to the script; it will calculate the difference between those dates and send back the result.

    function ConvertDate(end, start){

    var End = new Date(end)
    var Start = new Date(start)
    var Duration = End-Start
    var Duration = Duration/1000/60

    ConDuration= new XMLDate(Duration)
    return ConDuration.getSCDateTimeString()
    }

    Save this to the Script Library and call it from anywhere. Just send it your end time and your start time and the script takes care of the rest.
  • Another top-notch answer! Works for my case, thanks Jacob.

    I only wish I saw your reply sooner, now I have to dump my long js code lines which does the same thing :)
  • Jacob,

    Does this code also allow me to specify a date fields in place of your arguments below? (i.e. start.time and end.time instead of end, start)?

     

    function ConvertDate(end, start){

    var End = new Date(end)
    var Start = new Date(start)
    var Duration = End-Start
    var Duration = Duration/1000/60

    ConDuration= new XMLDate(Duration)
    return ConDuration.getSCDateTimeString()
    }

    -----------------------------------------------------------------------------------------------------------------------------------------

    Also, I have a JS function within Script Library, what would be the syntax for calling the function from the Incident Task workflow within Process Designer?

     

    Dwalk