Date format

Rishabh_N
Tera Contributor

In a catalog item, I have a date field where the format appears as dd/mm/yyyy for me, which is causing my script to not execute properly. However, when I impersonate another user, the date format changes to yyyy/mm/dd, and the script executes fine.

I checked System Properties, where the date format is set to yyyy/mm/dd, but for my account, it still shows dd/mm/yyyy. I’m not sure if I made any changes earlier.

Can someone help me understand why this is happening and how to fix it so that my date format also appears as yyyy/mm/dd?

Thanks in advance!

3 ACCEPTED SOLUTIONS

SN_Learn
Kilo Patron
Kilo Patron

Hi @Rishabh_N ,

 

Please check the user preference in your account:

SN_Learn_1-1741238280747.png

 

Under Language and Region:

 

SN_Learn_0-1741238238274.png

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

surajnikam111
Tera Guru
Tera Guru

Hi @Rishabh_N ,

You can use below script to format date field:

 

var date = new GlideDate();// replace new GlideDate() with the incoming date
var dateNew = date.getByFormat('yyyy/MM/dd'); // now use the dateNew to set the field value

 

Regards,

Suraj

View solution in original post

@Rishabh_N 

no scripting required. you can simply use UI policy and you need not worry about the date format

No Code date validations through (Catalog) UI Policies 

use this in UI policy condition

Your Date relative before 7 days from now

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

View solution in original post

6 REPLIES 6

@Rishabh_N 

no scripting required. you can simply use UI policy and you need not worry about the date format

No Code date validations through (Catalog) UI Policies 

use this in UI policy condition

Your Date relative before 7 days from now

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

surajnikam111
Tera Guru
Tera Guru

Hi @Rishabh_N ,

You can use below script to format date field:

 

var date = new GlideDate();// replace new GlideDate() with the incoming date
var dateNew = date.getByFormat('yyyy/MM/dd'); // now use the dateNew to set the field value

 

Regards,

Suraj