- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 03:45 AM
Hi All,
I want to update the field 'Planned End Date' with 'current DateTime + 4 hrs'. For this, I have used the below code:
var date = gs.nowDateTime();
var end= new GlideDateTime(date);
var hours = 60*60*4;
end.addSeconds(hours);
The issue is when I am using the above code then my 'Planned End Date' field get populated with 'current DateTime + 6 hrs'. It will automatically add 2 extra hours even though I am adding seconds according to 4 hrs.
My User's Timezone is in CET. I want the value according to user's timezone.
Could anyone tell me how to fix this issue?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 04:44 AM
Just try this
var gdt = new GlideDateTime();
var hours = 60*60*4;
gdt.addSeconds(hours);
gs.print(gdt);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2022 12:16 AM
you can also use add with a time object for adding hours like below.
var gdt = new GlideDateTime();
var gtime = new GlideTime();
gtime.setValue("04:00:00"); // 4 hours
gdt.add(gtime);
gs.print(gdt);
// just make sure, that you never mix setDisplayValue/getDisplayValue with objects without them.
// best practice is to use the local time, as servicenow will automatically convert it when needed.