- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 10:30 AM
I have a date in string form from an outside source: 2022-01-06T08:31:35
I need to parse this date to only capture 2022-01-06. Everything else can be thrown out. How can I script this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 10:59 AM
Hi there,
Not sure if this is 100% correct, have to search... though it does work.
var input = ' 2022-01-06T08:31:35';
var gdt = new GlideDateTime(input).getDate();
gs.info(gdt);
*** Script: 2022-01-06
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 10:59 AM
Hi there,
Not sure if this is 100% correct, have to search... though it does work.
var input = ' 2022-01-06T08:31:35';
var gdt = new GlideDateTime(input).getDate();
gs.info(gdt);
*** Script: 2022-01-06
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 11:04 AM
var input = "2022-01-06T08:31:35";
var datePart = input.split("T")[0];
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 11:06 AM
Hello , Try something like this for example . Not tested but give a try by running on background script.
Example:
var date = new Date("2013-03-10T02:00:00Z");
date.toISOString().substring(0, 10)
Incase the Date doesn't work use the servicenow one GlideDate()
Mark my Answer as Correct and Helpful if it helps