- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 12:50 PM
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.
Anyone able to help me figure out how to get both into the same timezone?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:31 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:13 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:15 PM
use getDisplayValueInternal()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:41 PM
Looks like you and Brad did the same thing of removing the gs.nowDateTime().
Thanks for your quick reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:31 PM
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);