Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

I want to Change the Date format from YYYY/MM/DD To MM/DD/YYYY on Catalog form

Not applicable

HI There,

 

On Catalog Item form Now I have date variable format is YYYY/MM/DD to MM/DD/YYYY

 

Can anyone please help me how to get the solution for this.

PriyaSm_0-1703139156841.png

 

Thanks,

 

5 REPLIES 5

AnveshKumar M
Tera Sage

Hi @Community Alums 

This display format is governed by the user preferences/system default.

 

As far as I know, there is no attribute where we can change the data format.

 

 

If you want to convert this value to a different format for your backend processing, we can do that.

 

Please mark my answer helpful and accept as a solution if it helped 👍✅

Thanks,
Anvesh

AniketC85155510
Kilo Patron

Hello @Community Alums ,

 

Please refer the link below and let me know how it works for you.

 

Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Regards,

Aniket

Not applicable

 @Ankur Bawiskar,

 I have used the Script Include that you have mentioned to someone's question, for setting the Date Format,

 

 

var MyConversion = Class.create();
MyConversion.prototype = {
	initialize: function() {
	},

	convertDateFormat: function(){

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

	},

	type: 'MyConversion'
};

 

 

Could you please help me with the Onchange Client script, for getting the date format.

 

Thanks,

 

 
 
 
 

Hello @Community Alums ,

 

Please give a try to the below script once and let me know how it works for you.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '')
        return;

    var dateField = g_form.getControl('your_date_variable'); // Replace 'your_date_variable' with the actual variable name
    var currentDate = dateField.value;

    if (currentDate) {
        var formattedDate = convertDateFormat(currentDate); // Call your date conversion function
        dateField.value = formattedDate;
    }
}

function convertDateFormat(incomingDate) {
    // Your date conversion logic here
    // You can use the same logic as in your Script Include

    // Example:
    var gdt = new GlideDateTime();
    gdt.setDisplayValue(incomingDate + ' 00:00:00');
    var gd = new GlideDate(); 
    gd.setValue(gdt.getDate());
    return gd.getByFormat("MM/dd/yyyy");
}