Convert date format from YY-MM-DD to DD-MM-YYYY

pujitha K
Tera Contributor

Hi All,

 

In record producer we have one variable which is Date type, in employee center it is displaying as YY-MM-DD

pujithaK_0-1753966546831.png

 

I have requirement to change this from YY-MM-DD to DD-MM-YYYY in employee center form view and on the request information on the record should show in DD-MM-YYYY format.

 

I created script include and on change client script.

 

Script include.

var ValidfromCreateaNewCostCenter = Class.create();
ValidfromCreateaNewCostCenter.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
   
    convertDateFormat: function() {
        gs.log('Pu date1');

        var incomingDate = this.getParameter('sysparm_format');
        var format = 'yyyy/dd/MM';
        var gdt = new GlideDateTime();
        gdt.setDisplayValue(incomingDate, format);
        var gd = new GlideDate();
        gd.setValue(gdt.getDate());
        return gd.getByFormat("MM/dd/yyyy");

    },

    type: 'MyConversion'
});
 
On change Client Script on variable 
 
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

alert('new value ' + newValue);
 var ga = new GlideAjax('x_bcb_mdm.ValidfromCreateaNewCostCenter');
   ga.addParam('sysparm_name', 'convertDateFormat');
   ga.addParam('sysparm_format', 'newValue');
   ga.getXMLAnswer(function(response){

    alert('gp ' + response);

    var FormattedDate = response;
    g_form.setValue('variable_name', FormattedDate);
   });
 
I have tried with above scripts the logs in script include are not showing and in client script alert response is showing as null 
7 REPLIES 7

@pujitha K 

that's now how the behavior will be.

Even if the format is DD-MM-YYYY but user can change the format from user preferences.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

 

It is not about user user preferences right now variable type is date and format is YYYY-MM-DD

As mentioned above current functionality is PFB example snapshot.

pujithaK_0-1754028140734.png

 

Client want that to be changed to DD-MM-YYYY this is complete only when user able to see DD-MM-YYYY .

 

Now user requirement is to be in format Example- 01-08-2025

@pujitha K 

how it's behaving with users with different date format?

what's the requirement in that case when user's have different date format?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader