how to change the date type field from yyyy-mm-dd to dd/mm/yyyy for a particular field?

avi_hb
Tera Contributor

how to change the date type field format from yyyy-mm-dd to dd/mm/yyyy for a particular field on a particular table without changing system properties or without changing the field type to string?

avi_hb_0-1684314567985.png

Here in this scenario, I want payment reference field to display in dd/mm/yyyy format, payment reference is a date field?

already tried date.getbyformat its only changing string field, but not helping with the date field.

4 REPLIES 4

Manmohan K
Tera Sage

Hi @avi_hb ,

 

You can create a on change client script like below

var ga = new GlideAjax('PGIncidentAJAX');
ga.addParam('sysparm_name', 'getGMT');
ga.addParam('sysparm_date_time', newValue);
ga.getXML(processResponse);

function processResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('payment_reference', answer); 
}

 

And a script include similar to below

var PGIncidentAJAX = Class.create();
PGIncidentAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getGMT: function(){
		var dt = this.getParameter('sysparm_date_time');
		var gdt = new GlideDateTime();
		gdt.setDisplayValue(dt);
		var date = gdt.getValue().split(' ');
		var dateonly = new GlideDate();
		dateonly.setValue(date[0]);
		var last = dateonly.getByFormat('dd/MM/yyyy') + " " + date[1];
		return last;
	},
	type: 'PGIncidentAJAX'
});

 

Manmohan K
Tera Sage

Manmohan, I want to display the date in dd/mm/yyyy format for a DATE FIELD, as mentioned above, in the example for which the link you have shared its for the string field.

avi_hb
Tera Contributor

@Mike Patel , @Chuck Tomasi   Can you please help me with this requirement?