GlideDateTime.subtract return negative value in days for Duration Field Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2020 09:00 AM
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:
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2021 07:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2021 03:15 AM
Hi Mark,
Just change
var datediffer = GlideDateTime.subtract(closed, opened);