
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2020 07:23 AM
Hi all,
Is it possible to change the date format from:
8 September 2020
to
08/09/2020 - via a script? would then need to populate a date in a request item...
Thanks for your help
Regards
Rich
Solved! Go to Solution.
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:19 AM
Hi,
Try like this.
var termination_date = email.body.termination_date;
termination_date = termination_date.split(" ");
var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"];
//get the month
var mon = month.indexOf(termination_date[1].toString());
mon++;
var gdt1= new GlideDateTime();
gs.info("Date format is "+gdt1);
var dt = termination_date[2]+"-"+mon+"-"+termination_date[0]; //change to your system format here
var gdt = new GlideDateTime(dt);
//Now gdt contains the date in the SN format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2021 02:01 AM
Hi Asif,
I used the same script but its not capturing exact date from email body to Servicenow.
Email format --
<<<BEGIN>>>
Type=Request - Service
Requested Resolution Date=Thu, 13 May 2021 11:25:56 -0400
<<<END>>>
Script used--
var termination_date = parseBody("Requested Resolution Date=");
termination_date = termination_date.split(" ");
var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"];
//get the month
var mon = month.indexOf(termination_date[1].toString());
mon++;
var gdt1= new GlideDateTime();
gs.info("Date format is "+gdt1);
var dt = termination_date[2]+"-"+mon+"-"+termination_date[0]; //change to your system format here
var gdt = new GlideDateTime(dt);
//Now gdt contains the date in the SN format.
gdt1.setDisplayValue(dt);
cart.setVariable(item, 'requested_resolution_date', gdt1.getDate());
Variable date format is yyyy-mm-dd.
Could you please suggest.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 04:07 AM
Thank you Asifnoor!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 06:40 AM
Hi Asif,
I'll get the date as "6-Apr-22" from CSV and I'm using transform map. In script I want to convert it to MM-dd-yyyy. I'm unable to convert the year from 22 to 2022.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 02:37 AM
Hi Richard,
Check below link, it might help you
If my answer helped you in any way, mark answer as helpful and correct.
Thanks and regards,
Megha