Subtract X hours from given date/Time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 02:37 PM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 02:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 03:13 PM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 04:36 PM
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.