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

terry18
Kilo Contributor

if you are doing this through code you could try the following example.





//sample date string


var sampleDate = "Sat Jun 09 2007 17:46:21";




//function to format the date string



function formattedDate(date) {


      var d = new Date(date || Date.now()),


              month = '' + (d.getMonth() + 1),


              day = '' + d.getDate(),


              year = d.getFullYear();


      if (month.length < 2) month = '0' + month;


      if (day.length < 2) day = '0' + day;


      return [day, month, year].join('/');


}



//call it like so formattedDate(now)


document.write(formattedDate(now));


Terry,


Thank you for your help.



Is there different way to do this then code?



Shoaib


terry18
Kilo Contributor

Sorry im new to service-now. Maybe someone else has an easier way to fix the issue ??


Davina
Giga Contributor

Can i ask how the date is created? Is this by the end user - so do they input the date in the email or is this a time stamp with no room for human error?



Terry Slattery is quite right that you will need to write a function to convert the date into the applicable format.