Convert dd-mmm-yyyy to mm/dd/yyyy on Inbound Action

Jon S_
Giga Contributor

Not sure why I'm finding this so difficult but dates are my greatest weakness and greatly appreciate any help as I have searched endlessly and the glideDate's that I've tried have not worked.

I have an inbound script that I need to take a provided date in the body of the email notification and convert it to a different format and set it to just a string field. It is coming in as 10-Sep-2019 and needs to convert to 10/10/2019. The sender has no option to change their date format.

I know the script to apply it, without reformatting, would look like:

current.u_start_date = email.body.start_date

Thanks in advance!

1 ACCEPTED SOLUTION

Jon S_
Giga Contributor

Finally got it! I was doing my best to avoid what I used to have to do in the past like yours above. Thanks everyone.

var gd = new GlideDate();
gd.setDisplayValue(email.body.start_date, "dd-MMM-yyyy");
current.u_start_date = gd.getByFormat("MM/dd/yyyy");

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

 

Below link may help

 

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


Please mark this response as correct or helpful if it assisted you with your question.

Sanjiv - I'm having a hard time connecting the dots between my ask and that article and understanding how that would help.

Try below

var gdt = new GlideDate();
gdt.setDisplayValue('email.body.start_date', "dd-MMM-yyyy");
current.u_start_date = gdt;


Please mark this response as correct or helpful if it assisted you with your question.

Jon S_
Giga Contributor

Sanjiv - I had to remove the extra quotes to get it to work but the output is putting it into YYYY-DD-MM.

var gdt = new GlideDate();
gdt.setDisplayValue(email.body.start_date, "dd-MMM-yyyy");
current.u_start_date = gdt;

So it's starting as 15-Sep-2018 but outputting it as 2018-09-15 and I'm needing it to be 09/15/2018. Any other ideas?