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

Thanks Shishir...but I was wondering if I could leverage the system property glide.sys.date_format in my script include to make sure the format getting returned is dd/MM/yyyy. Any ideas?


You can not leverage the system property glide.sys.date_format in script include but you can try formatting the date in that way and check.


Naa mate, didn't work..used this below, but no luck...



gd.setValue(gdt.getValue()); //set value of GlideDate variable from the


GlideDateTime variable. Used this as I had to add months to a date field


depending on a client selected value


gd.getByFormat("dd/MM/yyyy");


return gd;



On Fri, Jun 2, 2017 at 4:28 PM, explorenow <


Hi Suhas,



I have tried in this way and it's working for me, you can also try and see if works for you as well,



Changed the date format in system properties -> system



find_real_file.png



then select the Date format in User profile as the below



find_real_file.png



Please have the below code.



Client Script:



function onLoad() {


  var dFormat = g_user_date_format;


  var tdayDate = formatDate(new Date(),dFormat);


  g_form.setValue('u_newdate', tdayDate);



  var ajax = new GlideAjax('MyNeededDateBy');


  ajax.addParam('sysparm_name', 'neededByDateTime');


  ajax.getXML(function () {


  var neededDate = ajax.getAnswer();


  g_form.setValue('u_mydate', neededDate);


  });


}




Script Include:


var MyNeededDateBy = Class.create();


MyNeededDateBy.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  neededByDateTime: function () {


  var neededDate = gs.nowDateTime();


  var gdt = new GlideDateTime(neededDate);


  gdt.setDisplayValue(neededDate, "dd/MM/yyyy hh:mm:ss");


  return gdt.getDisplayValue();


  },



  type: 'MyNeededDateBy'


});




Output:


find_real_file.png



Hope this helps.


Thanks mate, but for setting the date field format the value returns from a


script include. And new date () instantiates today's date... Tried using


the value from script include, didn't work.



On 2 Jun 2017 5:05 PM, "explorenow" <community-no-reply@servicenow.com>