get dateTime in local time

Kumar38
Kilo Sage

I need to calculate due date based on a schedule to assign SLAs to task.

This script shows my current date time as+4 hours in future .

var slaDays = 3;
var startDate = new GlideDateTime();
gs.info('ABC--startDate---' + startDate);
var days = parseInt(slaDays);
//assuming there are 9 business hours
days = days*9;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var end = schedule.add(startDate, dur);
gs.info('ABC--end---' + end);


//Output

*** Script: ABC--startDate---2022-04-12 05:29:34
*** Script: ABC--end---2022-04-15 15:00:00

//EXPECTING END DATE OUTPUT AS 04/15/2022 17:00:00
1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Have you tried using getDisplayValue() ?

var slaDays = 3;
var startDate = new GlideDateTime();
gs.info('ABC--startDate---' + startDate.getDisplayValue());
var days = parseInt(slaDays);
//assuming there are 9 business hours
days = days*9;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var end = schedule.add(startDate, dur);
gs.info('ABC--end---' + end.getDisplayValue());

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

Have you tried using getDisplayValue() ?

var slaDays = 3;
var startDate = new GlideDateTime();
gs.info('ABC--startDate---' + startDate.getDisplayValue());
var days = parseInt(slaDays);
//assuming there are 9 business hours
days = days*9;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //8-5 weekdays excluding holidays
var end = schedule.add(startDate, dur);
gs.info('ABC--end---' + end.getDisplayValue());

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

This same script is failing when

.getDisplayValue()

used in workflow. Any Idea why ?

Workflow activity will execute on behalf pf user who initiated/triggered that particular activity. And sometime it may execute on Behalf of system. So get display value will have different values based on user session.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

I am an admin and I tried using timer in the workflow too. Still failed.

what would be the fix ?