Need to Applying format on Date

Developer2764
Tera Contributor

Hi Community, Good Day!!!
I am working on a code that will display date.
I want to apply st with 1, nd with 2, rd with 3 and th with all others. I am using the below code:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var months=["jan","feb","march","april","may","june","july","sep","october","november","december"];
newValue= newValue.split("-",[3]);
var month=newValue[1];
var name=(months[month-1]);
var date2= newValue[0]+"-"+name+"-"+newValue[2];
g_form.setValue('u_date2',date2);
//Type appropriate comment here, and begin script below
 
}
and the output is:
Developer2764_0-1690226664798.png

thanks


3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Developer2764 

any reason why to have 2 fields to hold same information?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Developer2764
Tera Contributor

Hi @Ankur Bawiskar, this script is showing month's name and i want to show date with st and nd etc.
this is the requirement

 

@Developer2764 

I don't think just to show date in another format there has to be a separate field.

It unnecessarily increases the overhead of maintaining custom fields.

Please discuss this with your customer and your technical lead.

This requirement should have been pushed by the architect itself.

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