how can i covert this 26-Sep-2020 ( DD-MMM-YYYY ) to 2020-09-26 ( YYYY-MM-DD)

Davie
Giga Expert

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? 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

I have done reformatting of date in another thread few days below. Kindly check this link.

https://community.servicenow.com/community?id=community_question&sys_id=bb9e5519dbc750144aa5d9d96896...

Mark the comment as a correct answer and also helpful if it helps to solve the problem.

View solution in original post

3 REPLIES 3

asifnoor
Kilo Patron

Hi,

I have done reformatting of date in another thread few days below. Kindly check this link.

https://community.servicenow.com/community?id=community_question&sys_id=bb9e5519dbc750144aa5d9d96896...

Mark the comment as a correct answer and also helpful if it helps to solve the problem.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Steven Parker
Giga Sage

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