Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

calculate the weeks between the dates

siva58
Tera Contributor

calculte the weeks between the two dates by using business rules..

example:

these two are the dates

start date:

 End date:
 
the result(no.of weeks) will be populate in another field,
 
no.of week
 

 

 

1 ACCEPTED SOLUTION

Baala T
Mega Guru

Hi Siva,

PFB script,

var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2012-09-01 10:00:00");
var dur = new GlideDuration();
 
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2

gs.print(dur.getDisplayValue());
gs.print(dur.getDayPart());

var days = dur.getDayPart();
var weeks = parseInt(days/7);

gs.print(weeks);

 

Regards,
Bala T

View solution in original post

7 REPLIES 7

Baala T
Mega Guru

Hi Siva,

PFB script,

var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2012-09-01 10:00:00");
var dur = new GlideDuration();
 
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2

gs.print(dur.getDisplayValue());
gs.print(dur.getDayPart());

var days = dur.getDayPart();
var weeks = parseInt(days/7);

gs.print(weeks);

 

Regards,
Bala T

siva58
Tera Contributor

1.here two times "dur"  declared, it showing as error

var dur = new GlideDuration();
 
var dur = GlideDateTime.subtract(gdt1, gdt2); 

2, how to populate  that result in another field..

Check the script I shared; it should work fine

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

how to populate the result in another field;

find_real_file.png