Why is a GlideDate of 2016-06-27 returning as a GlideDateTime of 2016-06-26 05:00:00 PM?

SC10
Kilo Guru

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

1 ACCEPTED SOLUTION

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?



View solution in original post

14 REPLIES 14

top_tanti
Tera Expert

Here's the code I used for a record producer with variable effective_date and field due_date:



var dueDate = new GlideDateTime(producer.effective_date); // Convert the Effective Date var to GlideDateTime object


var time = new GlideTime();


time.setDisplayValue("17:00:00"); // Set the GlideTime object to 5:00PM as the end of business day


dueDate.add(time); // Add time to the current effective_date


current.due_date = dueDate; // Pass the new calculated value to the HR Case due_date field




Edit: This is what your code might look like:



var endDate = new GlideDateTime(producer.effective_date); // Convert the Effective Date var to GlideDateTime object  


var time = new GlideTime();  


time.setDisplayValue("17:00:00"); // Set the GlideTime object to 5:00PM as the end of business day  


endDate.add(time);


current.work_end = endDate;


My result for the new GlideDateTime is: 2062-12-24 12:49:25 PM



My code is as follows:



var actualEnddate = new GlideDateTime(current.variables.offboard_effectivedate); // Convert the Effective Date var to GlideDateTime object      


var time = new GlideTime();      


time.setDisplayValue("17:00:00"); // Set the GlideTime object to 5:00PM as the end of business day      


actualEnddate.add(time);    


current.work_end = actualEnddate;


What was your original value for offboard_effectivedate?


Good day,



The value used for that variable was: 2016-06-28



Thanks.