How to change Date Format from YYYY-MM-DD to DD/MM/YYYY on Portal?

Alfiya
Tera Contributor

So, I'm new to ServiceNow and I have this Date Type Field which I am using on a form on Service Portal.

  • So when the end user selects the date on Portal it shows selected date in format DD/MM/YYYY.
  • But when the end user submits the request, this format is changed to YYYY-MM-DD,
  • This is because this format (YYYY-MM-DD) is selected in the system properties, which I can not change , because this will make changes globally, which is not desirable.

 

So, after the submission of the request too I want the field to accept the date in the format DD/MM/YYYY only.

This I want on the catalog item form on Portal.

How can I do this?

Thanks!

6 REPLIES 6

Alp Utku
Mega Sage

You can write catalog client script to set the date format on Submit

 

var MyDate = g_form.getValue('your variable name') ;

var gdt = new GlideDateTime(myDate);

gdt.setDisplayValue("myDate","dd-MM-yyyy HH:mm:ss");//uses current user session time zone 

asifnoor
Kilo Patron

Hi,

Generally when a date is selected and stored in backend it will be stored in the system format which in your case is YYYY-MM-DD.

If you want to show it in a different format like in SP, then while fetching the date, you can use getByFormat function of GlideDate API. This will help you to get the format in the way you want instead of storing the date in different format.

Ref: https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideDateScope...

Mark the comment as a correct answer and also helpful if this has helped to solve the problem.

rahulpandey
Kilo Sage

Hi Alfiya,

If this is only about taking input from user DD/MM/YYYY on portal and not about how you are storing it.

I would suggest you to create a custom data field widget and add it to catalog a UI macro widget and hide the actual data field widget. 

Further you can write script to copy from user friendly date field to actual date field via g_form API.

For starters, refer below

https://www.esmalliance.com/2019/01/18/customisation-of-the-service-portals-date-and-time-picker/

How to embed widget in catalog item

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/build/service-portal/task/ui-macro-widget.html

I want to store the value in DD/MM/YYYY Format itself.