Calculate duration according to a specific schedule

MikeMU
Tera Contributor

Hello,

given 2 fields in project task table- "Planned end date" and "Planned start date" my task is to calculate the value of the field "duration" for a specific schedule. Is there a script or code segment that can help me achieve this?

Thanks in advance.

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@MikeMU You can use the subtract method to calculate duration between the planned start date and end date.

 

Here is the sample script.

 

var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
 
var dur = GlideDateTime.subtract(gdt1, gdt2); // Difference between gdt1 and gdt2
gs.info(dur.getDisplayValue());

 

Here is the output

 

2 Days 23 Hours

 

Source: https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideDateTimeAP...