Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Change date format of a catalog item variable date field

MelvinBulan
Tera Contributor

Is there a way I can change the date format to this kind of format?

MelvinBulan_0-1669632585724.png

 

When I select a date it becomes like this

MelvinBulan_1-1669632606135.png

This is my date variable

MelvinBulan_2-1669632616318.png

 

Is it possible to add something/configure this script? I have this script cause I had to make it so it wont select the past date. Would it be possible to add something to these scripts so it will change the format to dd-Month(or MM)-YYYY

 

onChange Script: 

MelvinBulan_0-1669633830137.png

 

Script Include: 

MelvinBulan_1-1669633852225.png

 

 

6 REPLIES 6

You can use getByFormat to change format of a date field. For example: 

 

var date = new GlideDate(); //Outputs today's date in format 2024-01-29

var date2 = date.getByFormat('dd. MMMM, YYYY') //This outputs 29. January, 2024. 

 

The getByFormat allows you to change the format quite a bit, for instance if you want a shorter output you could change it to ('dd. MMM, YY'). This would output 29. Jan, 24.

 

See the documentation for more info about it. 

https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G...

Robin Hogli
Tera Contributor

You can use getByFormat to change format of a date field. For example: 

 

var date = new GlideDate(); //Outputs today's date in format 2024-01-29

var date2 = date.getByFormat('dd. MMMM, YYYY') //This outputs 29. January, 2024. 

 

The getByFormat allows you to change the format quite a bit, for instance if you want a shorter output you could change it to ('dd. MMM, YY'). This would output 29. Jan, 24.

 

See the documentation for more info about it. 

https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G...