variable returning GMT while gs.nowDateTime() returns local timezone

conanlloyd
Giga Guru

I have a requirement to update a notification generator to have a scheduled time to send.  On the surface it looked easy as I just needed a timer in the workflow after the approval to wait until the requested date/time.  Here is my timer script, (forgive the log statements):

//Set variables
var userTime = current.variables.when_to_send;
var nowdt = new GlideDateTime(gs.nowDateTime());
gs.log("CDL: nowdt " + nowdt);
gs.log("CDL: userTime " + userTime);

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);

The problem is that when I run it, userTime is returning a time in GMT while nowdt is returning a time in my local EST! So instead of returning a value of approximately 400 seconds between the nowdt of 14:58:17 and the 15:05 of the userTime, it gave me what is below.

find_real_file.png

Anyone able to help me figure out how to get both into the same timezone?

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This revised script will show you the correct number of seconds in your answer log - just take out the gs.nowDateTime()

//Set variables
var userTime = current.variables.when_to_send;
var nowdt = new GlideDateTime();
//gs.log("CDL: nowdt " + nowdt);
//gs.log("CDL: userTime " + userTime);

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);

View solution in original post

5 REPLIES 5

Harsh Vardhan
Giga Patron

try now

 

var userTime = new GlideDateTime(current.variables.when_to_send);
var nowdt = new GlideDateTime();
gs.log("CDL: nowdt " + nowdt);
gs.log("CDL: userTime " + userTime.getDisplayValueInternal());

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);

 

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideDateScope...

use getDisplayValueInternal()

Looks like you and Brad did the same thing of removing the gs.nowDateTime().

 

Thanks for your quick reply!

Brad Bowman
Kilo Patron
Kilo Patron

This revised script will show you the correct number of seconds in your answer log - just take out the gs.nowDateTime()

//Set variables
var userTime = current.variables.when_to_send;
var nowdt = new GlideDateTime();
//gs.log("CDL: nowdt " + nowdt);
//gs.log("CDL: userTime " + userTime);

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);