Subtract X hours from given date/Time.

Kumar38
Kilo Sage

I have a script that calculates the due date , but it shows an extra 5 hours could be due to time zone difference.

How can I subtract 5 hours from the final datetime field?

 

var slaDays = current.variables.priority ;

var startDate = new GlideDateTime();

var days = parseInt(slaDays);
//assuming there are 8 business hours
days = days*9;
var dur = new GlideDuration(60 * 60 * 1000 * days);
var schedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); //8-5 weekdays excluding holidays


var dueDate = schedule.add(startDate, dur);

workflow.scratchpad.duueDate = dueDate;
3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

Hello

Use the below script

var gdt=new GlideDateTime(duedate); gdt.addSeconds(-432000);

var new_time=gdt.getValue();

Please mark answer correct/helpful based on impact

Raj  K
Tera Contributor

Hey,

 

If it's the time zone difference, then change the time zone in your instance to match the correct one.

 

Subtracting 5 hours will change the duedate.

Hope this helps!

Hitoshi Ozawa
Giga Sage
Giga Sage

Following will substract 5 hours.

var dur = new GlideDuration(60 * 60 * 1000 * days - 18000000);

Is (60 * 60 * 1000 * days) correct? Argument to GlideDuration() is in milliseconds.

60 sec/1 min * 60 min/hr * 1000 ms/s = 3600,000 ms/hr. Shouldn't this be multiplied by 9 hours/day (8-5) 

Substracting before using GlideSchedule because otherwise, the time may end up outside the scheduled time.