- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 12:24 AM
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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 02:00 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 02:15 AM
Glad to help.
Please mark response helpful as well.
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
02-21-2022 02:52 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 02:57 AM
Any specific reason you copied the same script which I shared and posted again?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 12:41 AM
ServiceNow will save datetime in yyyy-MM-dd HH:mm:ss format in server side.
Example:
var strDate = '02-02-2022';
var gdt = new GlideDateTime(strDate);
gs.info(gdt.getValue());
Execution result:
*** Script: 2022-02-02 00:00:00

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 12:42 AM
That is, there's no need to do any conversion or scripting to save the date in yyyy-MM-dd HH:mm:ss format.