How to convert current date time into ISO ISO8601 format: yyyy-MM-dd'T'HH:mm:ss'Z

lucky24
Tera Contributor

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

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for Response,

First I want to convert current date time Into ISO format.

I am using code like below

find_real_file.png

But In result I am getting undefined.

Then I have to subtract 10 minute from current date time.

Hi,

you want to send date/time which is subtracted with 10mins ? that is what you mentioned

you have now time i.e. End time

you can subtract 10mins from it and it will be From time

I already shared script for conversion so convert both and send

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I given From and to date in ISO formate

But I am getting error in response

find_real_file.png