- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 02:52 AM
I have used below code to convert the date format but didn't worked.
var gr = '09/27/2023';
var gd = new GlideDate();
gd.setValue(gr);
gs.info(gd.getByFormat("MM-dd-yyyy"));
But Getting below error in background script:
"Unparseable date: "09/27/2023": java.text.ParseException:"
Please help me on this!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 03:01 AM
Hi Ganesh,
Can you try below in bacgkground script once for a check.
var gr = '09/27/2023';
var gd = new GlideDateTime(gr).getDate();
//gd.setValue(gr);
gs.info(gd.getByFormat("MM-dd-yyyy"));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 02:59 AM
Hi there,
Where is this 09/27/2023 coming from? Can you provide more details? This is not what's actually stored in the XML of the record, correct?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article 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
10-28-2020 03:01 AM
Hi Ganesh,
Can you try below in bacgkground script once for a check.
var gr = '09/27/2023';
var gd = new GlideDateTime(gr).getDate();
//gd.setValue(gr);
gs.info(gd.getByFormat("MM-dd-yyyy"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 03:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 03:19 AM
updated script below
var gr = '09/27/2023';
var gdt = new GlideDateTime();
gdt.setDisplayValue(gr, "MM/dd/yyyy");
var formattedDate = gdt.getDate();
var time = new GlideDate();
time.setValue(formattedDate);
gs.info(time.getByFormat("MM-dd-YYYY"));
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader