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

Harsh Vardhan
Giga Patron

try now

 

setDurationFields();

function setDurationFields() {

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

if (current.u_duration.nil())

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

Harsh Vardhan
Giga Patron

can you also add log. if its not working .

 

validate the log. 

 

setDurationFields();

function setDurationFields() {

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

gs.info('Dates are '+ opened + ' '+ closed );

if (current.u_duration.nil())

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

gs.info('duration is  '+ datediffer.getNumericValue() );

current.u_duration = datediffer;
}

Hi Harshvardhan,

 

Thank you for showing interest in my case. I did what you have suggested and still the same

 

 
 

what are you getting in log ? did you check the timezone?

i had tested on my personal instance with same time and date in two different field and updated on duration type field, which updated 16 days .