Jump to content

Oridinals


rrdwitt

Recommended Posts

Hi all, here is the code I used, and it is working for half my issue.

But, I still need to find a way to get the "st" "th" and/or "nd" on the

end of the number. Any suggestions?

 

MyDate = DateFromString(Field("f123_DueToRenewDateString"));

return FormatDate(MyDate, "lm dd");

 

Right now, this returns ex. January 10, which is good but I need January 10th.

 

Yes, I have seen the other posts about ordinals, but it does not really make sense to me based on my current code. Thanks in advance.

Link to comment
Share on other sites

I grabbed an ordinal function from this post and modified it slightly (the v variable isn't necessary since a date will never be higher than 31 – much less 100). Then I just replaced the date with the returned value from the getOrdinal function for the matched date:

 

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return n + (s[(n-20)%10] || s[n] || s[0]);
}
MyDate = DateFromString(Field("f123_DueToRenewDateString")) ;
return FormatDate(MyDate, "lm dd").replace(/(\d+)$/, getOrdinal);

Link to comment
Share on other sites

So sorry, I appreciate your help tremendously, but I need the ordonial to reflect the day. So, my data cell says 5/13/17. Right now it is reflecting the year. I need it to be the day. Please. I also need that ordonial to be superscript.
Link to comment
Share on other sites

Please paste the code you're using. You've obviously changed it from what you originally posted since the 'FormatDate' function originally just output the month and day.

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return n + (s[(n-20)%10] || s[n] || s[0]);
}
MyDate = DateFromString(Field("f123_DueToRenewDateString")) ;
return FormatDate(MyDate,[color="Red"] "lm dd"[/color]).replace(/(\d+)$/, getOrdinal);

Link to comment
Share on other sites

function getOrdinal(n) {

var s = ["th","st","nd","rd"];

return n + (s[(n-20)%10] || s[n] || s[0]);

}

MyDate = DateFromString(Field("f123_DueToRenewDateString")) ;

return FormatDate(MyDate, "lm d").replace(/(\d+)$/, getOrdinal);

Link to comment
Share on other sites

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return n + (s[(n-20)%10] || s[n] || s[0]);
}
MyDate = DateFromString(Field("f123_DueToRenewDateString")) ;
return FormatDate(MyDate, "lm d").replace(/(\d+)$/, getOrdinal);

 

That doesn't have the year in it, either so I'm not sure why you're seeing the code reflect the year.

 

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return n + (s[(n-20)%10] || s[n] || s[0]);
}
MyDate = '5/13/17'; 
return FormatDate(MyDate, "lm d").replace(/(\d+)$/, getOrdinal); // May 13th

 

s there a way to superscript the ordonial? With a tag? </superscript>

Yes, you can use the 'superscript' to superscript the ordinal:

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return n [color="Red"]+ '<superscript>'[/color] + (s[(n-20)%10] || s[n] || s[0])[color="red"] + '</superscript>'[/color];
}
MyDate = DateFromString(Field("f123_DueToRenewDateString"));
return FormatDate(MyDate, "lm d").replace(/(\d+)$/, getOrdinal);

 

The below gives the you flexibility to add the year if you choose:

function getOrdinal(n) {
 var s = ["th","st","nd","rd"];
 return s[(n-20)%10] || s[n] || s[0];
}
MyDate = DateFromString(Field("f123_DueToRenewDateString"));
return FormatDate(MyDate, 'lm d') + '<superscript>' + getOrdinal(MyDate.getDate()) + '</superscript>'
     // + ' ' + FormatDate(MyDate, 'yyyy'); // Uncomment to include year.

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...