Change date format to YYYY-MM-DD 00:00:00Z format

Tapish Sharma
Tera Contributor

Hi, 

User is entering the date from record producer in dd-mm-yyyy format. In backend I want the fields to be in the YYYY-MM-DD 00:00:00Z format. How can I achieve this ? 

1 ACCEPTED SOLUTION

in flow then convert that and send

Sample script to convert normal date/time to ISO format

var myDate = '2022-02-21 00:00:00';
var gdt = new GlideDateTime();

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();

gs.info(isoDate);

Regards
Ankur

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

View solution in original post

16 REPLIES 16

Hi Ankur , I need to send date to another tool through API Integration which accepts the date in this YYYY-MM-DD format. 

Hi,

then during sending the API request you can convert.

Can you explain the script you are using?

your question was about converting format in record producer but now you are mentioning about API

Regards
Ankur

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

Yes Ankur, I thought if in first place only we can convert it into the said format then it will be easier. For Integration we have a flow 

in flow then convert that and send

Sample script to convert normal date/time to ISO format

var myDate = '2022-02-21 00:00:00';
var gdt = new GlideDateTime();

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();

gs.info(isoDate);

Regards
Ankur

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

Thankyou so much Ankur !