- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 11:14 PM
Hi Team,
We have integration with third party tool, where I have to Send Time Range From- to in body.
In from time I have to send Current Date Time in ISO ISO8601 format: yyyy-MM-dd'T'HH:mm:ss'Z then
I have subtract 10 minutes into current date time and have to pass in "to"
How can we achieve it?
Please Help me here
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 11:19 PM
Hi,
So you want to subtract 10mins and then convert to ISO?
if yes then do this
var gdt = new GlideDateTime('your date time');
gdt.addSeconds(-600); // 10 mins is 600 seconds
var dt = gdt.getValue().split(' ');
var f = dt[0].split('-');
var t = dt[1].split(':');
var event = new Date(f[0], f[1]-1, f[2], t[0], t[1], t[2]);
var isoDate = event.toISOString();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 03:26 AM
Hi,
it is adding extra zero; remove that and it would work
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 08:45 AM
Hi @Ankur Bawiskar
Thanks for your answer but I'm having an issue with it, literally copy pasted your code but the time is not correct
Running query in background script my timexone being London/Europe so utc+1 but the time is coming out as
2022-10-04T22:36:19.000Z
so this is 7 hours ahead of UTC, currently 16:36/15:36UTC
current UTC time is
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 08:46 AM
and I'm reluctant to just do as you have with the month as I'm not confident this will resolve itself when it goes past midnight or we enter a new year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2022 02:37 PM - edited 10-05-2022 02:41 PM
Hey Dave,
I am having the same trouble as you I believe, the split code seems to be setting the DateTime as PDT Timezone...
var crStart = current.getValue('start_date') gives 2022-10-08 18:00:00 - which is what i entered into the CR, FYI the system and user is set as GMT.
var crStartSplit = crStart.split(' ');
var crStartSplitD = crStartSplit[0].split('-');
var crStartSplitT = crStartSplit[1].split(':');
var cutoverStart = new Date(crStartSplitD[0], crStartSplitD[1]-1, crStartSplitD[2], crStartSplitT[0], crStartSplitT[1], crStartSplitT[2]);
gives Sat Oct 08 2022 18:00:00 GMT-0700 (PDT) - which appears to be defaulted to PDT
and therefore var cutoverIsoStart = cutoverStart.toISOString() gives 2022-10-09T01:00:00.000Z
which is clearly incorrect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2025 10:19 AM
@Dave Edgar / @Ankur Bawiskar I too face the same issue , do you have any solution for this issue?