Script to change date format from email

Richard Thomas2
Tera Contributor

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

1 ACCEPTED SOLUTION

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.

View solution in original post

13 REPLIES 13

asifnoor
Kilo Patron

Hi Richard

In the email script you can change the format like below.

var gdt = new GlideDateTime(current.your_field_name); //metnion your field name here
var dt = gdt.getDate().getByFormat("dd/MM/yyyy");
template.print(dt);

If this has answered your question, kindly accept my comment as a correct answer so that the question is moved to the solved list.

I see that you have marked my comment as helpful. Could you also mark it as correct so that the question is moved to the solved list.

Hi Asifnoor,

Thanks for your reply - I dont think I explained myself properly in the original question. I'm looking to convert the date from an email into a request item via an inbound action. The email has a date field that looks like this...

find_real_file.png

And I need to convert it into 11/09/2020.

Again, thank you for your response.

Regards

 

Richard