- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:29 AM
Hi,
I want to split Date & time from below value and pass it into a date time filed in the format yyyy-MM-dd HH:mm:ss.
2022-03-24T23:59:59.000+00:00
Please help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:50 AM
Hi,
the value you are having is in ISO format
use this to get only date/time
Script:
var iso = '2022-03-24T23:59:59.000+00:00';
var date = iso.split('T')[0];
var time = iso.split('T')[1].split('.')[0];
var dateTime = date + ' ' + time;
gs.info(dateTime);
Output:
[0:00:00.062] Script completed in scope global: script
Script execution history and recovery available here
*** Script: 2022-03-24 23:59:59
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
04-07-2021 05:37 AM
Assuming that you never care about timezone and you're always wanting just the time/date you can pull it out directly... in this code, you'd want to put the gdt object into your field:
var date = "2022-03-24T23:59:59.000+00:00"
var dateonly = date.substring(0,10);
var timeonly = date.substring(11,19);
var formattedDateTime = dateonly + " " + timeonly
var gdt = new GlideDateTime(formattedDateTime);
If you do care about the timezone (ie, you're going to get stuff in that isn't +00:00), you'll need to be a bit more complex about it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:58 AM
Hi,
I have just uploaded the output of the code.
*** Script: 2022-03-24 23:59:59
Thanks,
Vikas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 05:50 AM
Hi,
the value you are having is in ISO format
use this to get only date/time
Script:
var iso = '2022-03-24T23:59:59.000+00:00';
var date = iso.split('T')[0];
var time = iso.split('T')[1].split('.')[0];
var dateTime = date + ' ' + time;
gs.info(dateTime);
Output:
[0:00:00.062] Script completed in scope global: script
Script execution history and recovery available here
*** Script: 2022-03-24 23:59:59
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
07-22-2022 10:00 AM
I have a similar requirement, but mine has to be a dynamic value getting the created at field which is in UTC like above and autopopulate/update on the custom field on the incident table.
Could you help me how to pass the value dynamically?
var iso = '2022-03-24T23:59:59.000+00:00'; --> here it has pass the 'sys_created_at' value
var date = iso.split('T')[0];
var time = iso.split('T')[1].split('.')[0];
var dateTime = date + ' ' + time;
gs.info(dateTime); --> 'dateTime' should be updated on the 'u_incident_occured' field on the incident table.
Any pointers would help me.