Changing date format in Service Portal Catalog Item Variable from "dd/MM/yyyy" to "MM/dd/yyyy"

Von Naval
Tera Contributor

Hello. I have a catalog item that has a variable date field called Expected Date (expected_date) where it inputs a date with the default format of "DD/MM/YYYY".

VonAubreyNava_0-1676941791938.png

I want to make it so that the default value and any other value inputted in this field is always in a "MM/DD/YYYY" format without the need to change the System Property of the date format in the instance.

 

Is there any way to achieve this?

10 REPLIES 10

I have tried that already with a script include and client script with GlideAjax. It doesn't work for me unfortunately even after double-checking the code and all.

Hi @Von Naval Could you please share what  have you done so far and please share screenshots.
So I can help you to resolve your issue.

Thank you

Vallabh Baradk2
Giga Guru

Hi Von ,

 

Please try below code, use getByFormat() method of GlideDate api.

 

 var formatdate= day.getByFormat("MM-dd-yyyy");

 

Thank you,

Vallabh

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Von Naval 

the formats will change based on user's date format.

for your case you need to update the default system date format but it will be impact entire instance wherever date fields/variables are used.

I won't recommend that.

Inform the customer about the same.

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, I have a requirement to override user date format and set the system date format in a record producer variable. Any thoughts? 

 

For instance,  the systeam date format is DD/MMM/YYYY; a user has set the date preference to mm/dd/yyyy.

Now in the Record producer date variable the format should be DD/MMM/YYYY for all users irrespective of their preference. 

 

Please advise