- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:28 PM
Hi,
How to add hours to a Date/Time value.
I want to add 13 hours to the below Time format.
**4beginNextWeek===>2016-08-08 04:00:00
I have tried this Its din't work.
var beginNextWeek = new GlideDateTime(gs.beginningOfNextWeek());
gs.log("**4beginNextWeek===>"+beginNextWeek);
var splitDate = beginNextWeek.split("-"); // Split Catalog Date into year, month, day
var termDate = new Date(splitDate[0],splitDate[1]-1,splitDate[2]); // Avoid timezone issues, but month starts at 0
termDate.setHours(14); // 5:00 p.m. EST (2:00 p.m. PST by default)
gs.log("**4termDate===>"+termDate);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:49 PM
You might want to use getDisplayValue() to get in the user's time zone
var gdt = new GlideDateTime(gs.beginningOfNextWeek());
var hours = 60*60*13;
gdt.addSeconds(hours);
gs.print(gdt.getDisplayValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:32 PM
Hi Lakshmi,
Use gs.hoursAgo() with a negative value to go forward in time.
See the example in section 3.3.0 here
GlideSystem Date and Time Functions - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:35 PM
I would suggest the GlideDateTime functions to help with this. More importantly the addSeconds('46800') as a way to add the correct time value.
GlideDateTime - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:42 PM
Better idea Jake! Thanks.
Here's an example how that might be done.
var beginStr= '2016-08-08 04:00:00';
var beginNextWeek = new GlideDateTime(beginStr);
var hours = 60*60*13;
beginNextWeek.addSeconds(days);
gs.info('new time=' + beginNextWeek.getValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2016 01:49 PM
You might want to use getDisplayValue() to get in the user's time zone
var gdt = new GlideDateTime(gs.beginningOfNextWeek());
var hours = 60*60*13;
gdt.addSeconds(hours);
gs.print(gdt.getDisplayValue());