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?
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));
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>’);
Regards,
S