Highlighted
Absent Member.
Absent Member.
1993 views

calculate date duration in js

Jump to solution
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.
0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..
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.

View solution in original post

3 Replies
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..
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.

View solution in original post

Highlighted
Absent Member.
Absent Member.
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 🙂
0 Likes
Highlighted
Frequent Visitor..
Frequent Visitor..

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.