How to convert date format

sheths
Kilo Explorer

Hello all,

I have an inbound action which reads content of the email and populates a table with the information from the email body.

My issues is that the email contains long format date e.g. 24th March 2014 at 23:59hrs and I need to convert this to short format dd/mm/yyyy so it can populate date field on the form.

Appreciate any help with this.

Thank you.

20 REPLIES 20

arnabwa
Giga Guru

Hi sheths,



This will do the work for you. I have implemented this just a week ago for a requirement in inbound action same as your requirement. It works perfect. For me the incoming date format was a little different   but I have modified the code according to your need. Here it is :



var str = "24th March 2017";


var arr1 = str.split(" ");


var dArr = arr1[1];


var rmonth = '';



              if (dArr.toLowerCase() == 'january')        


                      rmonth = '01';


              if (dArr.toLowerCase() == 'february')        


                      rmonth = '02';


              if (dArr.toLowerCase() == 'march')        


                      rmonth = '03';


              if (dArr.toLowerCase() == 'april')        


                      rmonth = '04';


              if (dArr.toLowerCase() == 'may')        


                      rmonth = '05';


              if (dArr.toLowerCase() == 'june')        


                      rmonth = '06';


              if (dArr.toLowerCase() == 'july')        


                      rmonth = '07';


              if (dArr.toLowerCase() == 'august')        


                      rmonth = '08';


              if (dArr.toLowerCase() == 'september')        


                      rmonth = '09';


              if (dArr.toLowerCase() == 'october')        


                      rmonth = '10';


              if (dArr.toLowerCase() == 'november')        


                      rmonth = '11';


              if (dArr.toLowerCase() == 'december')        


                      rmonth = '12';


gs.log("month is:" +rmonth);


var date=arr1[0].substring(0,2);


gs.log("date is :" +date);


var year=arr1[2];


gs.log("year is" +year);


gs.log(date+"/"+rmonth+"/"+year);



Please let me know if you face any issue.



Thank you,


Arnab