GlideDateTime.subtract return negative value in days for Duration Field Type

mark141230
Tera Expert

Hi Guys,

 

Need your assistance as to why the result of my GlideDateTime.subtract returns negative values on days for the duration field type that I created. I have created a field name "Duration" which is a duration field type and I have 2 Date/Time Fields

Target Start Date and Target End Date, this are scoped application so I use the GlideDateTime.subtract to get the difference of 2 fields unfortunately it return negative result on days for the duration field. 

Please see my script below:

setDurationFields();

function setDurationFields() {

var opened = new GlideDateTime(current.u_target_start_date.getDisplayValue());
var closed = new GlideDateTime(current.u_target_end_date.getDisplayValue());

if (current.u_duration.nil())

var datediffer = GlideDateTime.subtract(opened,closed);
current.u_duration = datediffer;
}

 

and this is the screenshot of the result:

 

find_real_file.png

Thanks in Advance

6 REPLIES 6

prathamesh5
Mega Contributor

hello,

 

did you find the solution on this?

Currently i'm facing similar issue, but the time converted in seconds is coming as negative.

find_real_file.png

 

Help me , if you encountered this?

 

Regards.

nickanice
Tera Contributor

Hi Mark,

 

Just change

var datediffer = GlideDateTime.subtract(closed, opened);