- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 09:42 AM
Hey community, i seem to have trouble with this conversion.
I've having to update an connection with Jira to send YYYY-MM-DD but the script include already written and i don't want to mess with too much as it is set to take the display value of the form fields so is getting date as 26-Sep-2020 ( DD-MMM-YYYY )
I want to reformat to 2020-09-26 ( YYYY-MM-DD) so Jira can accept the date format.
Can it be done?
One solution i thought to have was to push the date value to a string field then pass that through to the script include to reformat it from 2020-09-26, is that the easiest and best option?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 09:45 AM
Hi,
I have done reformatting of date in another thread few days below. Kindly check this link.
Mark the comment as a correct answer and also helpful if it helps to solve the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 09:45 AM
Hi,
I have done reformatting of date in another thread few days below. Kindly check this link.
Mark the comment as a correct answer and also helpful if it helps to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 10:17 AM
Hi,
Since you are already getting the value in the DD-MMMM-YYYY format please convert it and then send
refer below sample script
var input = '26-Sep-2020';
var gdt = new GlideDateTime();
gdt.setDisplayValue(input, "dd-MMMM-yyyy");
gs.info(gdt.getDate());
Output: 2020-09-26
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
09-18-2020 10:41 AM
I always convert the dates like this before I compare them in an IF statement...I just did this yesterday before comparing the "Expected Start Date" variable we have against today's date:
//Getting the Expected Start Date in the format for evaluation
var jsStartDate = new Date(g_form.getValue('expected_start_date'));
var jsStartDateOnly = (jsStartDate.getMonth()+1) + "-" + jsStartDate.getDate() + "-" + jsStartDate.getFullYear();
//Getting today's date in the format for evaluation
var jsToday = new Date();
var jsTodayDate = (jsToday.getMonth()+1) + "-" + jsToday.getDate() + "-" + jsToday.getFullYear();
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven