How to set Date Variable in MM/dd/YYYY format using onChange Client Script

Shraddha Kadam
Mega Sage

Hello All,

On the RITM form I want to update the date variable. When I update the date variable the date is in the 'yyyy/dd/MM' format. I want the date variable is in the 'MM/dd/yyyy' format using onChange client script.

Anyone please help me.

I will appreciate the response.

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.
1 ACCEPTED SOLUTION

@Shraddha Kadam 

GlideAjax Example

Use this script include and send the value which is in yyyy/dd/MM 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'
};

Regards
Ankur

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

View solution in original post

15 REPLIES 15

Glad to help.

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

Hi Ankur,

From your answer above, How to change the date format of a variable to logged in users date format? Could you please help me on this.

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

@Reddy

Can you post a new question with complete details in that?

This thread is quite older one

Regards
Ankur

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

Hello Ankur,

Can you please provide the onchange client script for the above mentioned script include. Thank you.

Can u post the client script also ..I am not able to get date format