How do I format the day to say 1st 11th 23rd

I am working on the project where my data point for date fields is passed as mm/dd/yyy.

My goal to get date and format to say 1st, 12th, 23rd?

Any suggestions?

Hi Katie,

This is what I could come up with.

function ordinal(n){return[“st”,“nd”,“rd”][((n+90)%100-10)%10-1]||“th”;}

var date = record.fields.Date;
var newDate = formatter.dateShort(date);
var day = parseInt(newDate.substring(8, 10), 10);

results.html(day+ordinal(day));

Download

EDIT: I thought you might want to superscript the ordinal. Updated code and sample template below.

function ordinal(n){return[“st”,“nd”,“rd”][((n+90)%100-10)%10-1]||“th”;}

var date = record.fields.Date;
var newDate = formatter.dateShort(date);
var day = parseInt(newDate.substring(8, 10), 10);

results.html(day + ‘<sup>’ + ordinal(day) + ‘</sup>’);

Download

Regards,

S