- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2016 10:57 AM
When I convert a variable GlideDate field, which is holding a value of 2016-06-27, it is returning as 2016-06-26 05:00:00 PM. Any idea why this would be?
I am doing this with the following script:
var endDate = new GlideDateTime(current.variables.effective_date); //effective_date is my GlideDate variable
current.work_end = endDate; //work_end is an OOB field on task, which I have on my RITM for this workflow
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 01:48 PM
Robert,
var gdt = new GlideDateTime();
gdt.getTZOffset();
I work in Mountain Time, but our ServiceNow system time is set for Pacific so mine also also resolves to -2520000 (-7 hours in milliseconds)
My problem, and I think Shane's too, is that I am starting with a GlideDate, e.g. 2016-06-29. I'm performing calculations with this value and using it to update another GlideDate. These calculations involved both GlideDate and GladDateTime variables. If I didn't do this my result was always a day early.
// If the input dp_retention_date is 2016-06-29, gdt is '2016-06-28 17:00'.
var gdt_ret = new GlideDateTime(current.dp_retention_date);
// This adds 7 hours => '2016-06-29 00:00:00'
// If not negated, the result would be '2016-06-28 10:00'.
gdt_ret.add(gdt_ret.getTZOffset() * -1);
Thanks.
ps - How did you format the code in your post?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2016 11:55 PM
Try this method: getTZOffset(). It will account for the time zone offset:
var endDate = new GlideDateTime(current.variables.effective_date); //effective_date is my GlideDate variable
endDate.add(endDate.getTZOffset());
current.work_end = endDate; //work_end is an OOB field on task, which I have on my RITM for this workflow
Reference: GlideDateTime - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 11:53 AM
I was having the same problem as the OP, and Robert's suggestion solved my problem.
However, I had to negate end.Date.getTZOffset() to add time, because our TZ offset is negative.
var endDate = new GlideDateTime(current.variables.effective_date); //effective_date is my GlideDate variable
endDate.add(endDate.getTZOffset() * -1); // Negate the offset to add time.
current.work_end = endDate; //work_end is an OOB field on task, which I have on my RITM for this workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 01:20 PM
I am in Vancouver Canada, wherein we are GMT-8 and daylight savings. Would I need to negate any time on my TZoffset?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 01:26 PM
I'm in California - PST(-8)/PDT(-7) which is negative, and it works correctly for me as I showed it. I'm surprised Bradley had to make that change, but I'm glad that he found a solution.
var gdt = new GlideDateTime();
gdt.getTZOffset();
This code resolves to "-25200000" for me so it is already negative when I add it to the GlideDateTime object. This is the correct offset for my current daylight savings time:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 01:43 PM
Something isn't adding up.
I chose a date in my offboard_effectivedate GlideDate variable for today, which shows up in the variable as 2016-06-29.
My workflow is using the following to convert to GlideDateTime, and set "work_end" GlideDateTime field:
var actualEnddate = new GlideDateTime(current.variables.offboard_effectivedate); // Convert the Effective Date var to GlideDateTime object
actualEnddate.add(actualEnddate.getTZOffset());
current.work_end = actualEnddate; //work_end is an OOB field on task, which I have on my RITM for this workflow
The end result for work_end (labelled as Actual End Date) is: 2016-06-28 10:00:00 AM
The code looks fine, any idea where the snafu might be?