- 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:40 PM
Thanks Brad!! crazy to think it was that simple but I got the right number of seconds back now. Just have to wait until 4:45 to see if the notification fires off.