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

If you use timer then it will run on behalf of System. and will take system time.

Not sure why same is not working for admin, have you tried with timer with end user impersonation?

 

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

I tried no impersonation with any other user.