Date Calculations using client script

umaaggarwal
Giga Guru
Giga Guru

I have 2 datetime fields ( i.e. start date and end date)  on incident form , I want to calculate if end date -start date in > 90 and if yes, I want to perform some action. I do not want to use server side script. How can I achieve this ?

 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi Uma,

Kindly refer to this link, which takes care of date calculations using client script.

https://community.servicenow.com/community?id=community_question&sys_id=8c8ccf9adbf7a3045129a851ca96...

Mark the comment as a correct answer and also helpful once worked.

View solution in original post

3 REPLIES 3

asifnoor
Kilo Patron

Hi Uma,

Kindly refer to this link, which takes care of date calculations using client script.

https://community.servicenow.com/community?id=community_question&sys_id=8c8ccf9adbf7a3045129a851ca96...

Mark the comment as a correct answer and also helpful once worked.

sandeep24
Tera Guru

Use below code

 

var my_start_gdt = new GlideDateTime();

var my_end_gdt = new GlideDateTime();

 

my_end_gdt.setValue('2019-09-02');

 

var days_between = parseInt(gs.dateDiff(my_start_gdt.getDate(),my_end_gdt.getDate()));

//days between two days

var day_of_the_week = my_start_gdt.getDayOfWeekUTC();

//day of the week

var number_of_weekends = parseInt((days_between+day_of_the_week)/7);

//calculate weekend

var days_between_without_weekends = days_between - (number_of_weekends*2);

 

gs.log(days_between_without_weekends)

Dubz
Mega Sage

I know this question is already solved but the link below details a whole bunch of useful glidedatetime client script functions all running off the same script include:

https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f96...