Jump to content

Including Ordinal when Formatting Date


-Lisa-

Recommended Posts

No, but if you search the web for "JavaScript ordinals", you'll find lots of functions to do that, such as this one:

function getOrdinal(n)
{
   var s = ["th","st","nd","rd"];
   var v = n % 100;
   return s[(v-20)%10] || s[v] || s[0];
}

You can use it in a rule like this:

var theDate = Today();
var dayOfMonth = theDate.getDate();
var dayWithOrdinal = getOrdinal(dayOfMonth);
return FormatDate(theDate, "EE, MMM d") + dayWithOrdinal + FormatDate(theDate, ", yyyy");

Adding this functionality to FormatDate wouldn't be a bad enhancement idea for FusionPro, although such ordinals are obviously specific to English, and not all of our users, and certainly not all output files, are English-based. Different languages do ordinals much differently:

https://en.wikipedia.org/wiki/Ordinal_indicator

Edited by Dan Korn
Added note about ordinals in other languages.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...