How to change the date format on a specific field from short (MM/DD/YYYY) to long (MMM DD, YYYY)?

Pooja Reddy
Kilo Contributor

Hello,

I need to change the format of a specific date field on an HR case form from short (MM/DD/YYYY) to long (MMM DD, YYYY).For instance, 03/28/2108 should be March 28, 2018. I need to change the date format only for a single field and not across the system (I am on Kingston)

 

I tried creating a new System Property (long_date_format) and adding it to the Attribute in the Dictionary Entry of the field, but couldn't get it to work. I am thinking I might need to use a script include, but I am new to scripting. So before I try that, first wanted to check with you folks to see if there is an easier solution. If anyone could point me in the right direction, that would be really helpful!!

 

Many thanks!!

 

 

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage
  • Create a New Field called 'Long Date' of type String
  • Click 'Advanced View'

find_real_file.png

  • On 'Calculated Value' tab, check 'Calculated'

find_real_file.png

  • Insert the code below into the 'Calculation' field, substituting 'resolved_at' with your field
(function calculateLongDate(current) {
	var gDateTime = new GlideDateTime(current.resolved_at.getDisplayValue());
    var gDate = gDateTime.getDate();
	var longDateTime = gDate.getByFormat('MMMM dd,YYYY');
	return longDateTime;  
})(current);
  • Add the field to the form, under your Date field (example below)

find_real_file.png

Date/Time formats are documented here.

Similar to the Business Rule solution, it only updates on form load.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

12 REPLIES 12

Hi Paul,

The suggested script worked for me. Can you also let us know how the time entered in the field "Resolved" can be changed to "5.30PM".

4 years later, still helpful. Many thanks!

This is 'gold'.

Thank you.