rrdwitt Posted April 11, 2017 Share Posted April 11, 2017 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. Quote Link to comment Share on other sites More sharing options...
step Posted April 11, 2017 Share Posted April 11, 2017 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); Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 11, 2017 Author Share Posted April 11, 2017 Thank you Step, your help is very appreciated, but please see attached pic of error :-( Quote Link to comment Share on other sites More sharing options...
step Posted April 11, 2017 Share Posted April 11, 2017 Looks like you copy and pasted wrong. Try replacing all of the code in your rule editor with the all of the code from the code block in my post. Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 11, 2017 Author Share Posted April 11, 2017 That did it!!! Thank You!!!! Much obliged! Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 12, 2017 Author Share Posted April 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
step Posted April 12, 2017 Share Posted April 12, 2017 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); Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 12, 2017 Author Share Posted April 12, 2017 I apologize, I am still learning this coding. It was not intentional. Is there a way to superscript the ordonial? With a tag? </superscript> Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 12, 2017 Author Share Posted April 12, 2017 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); Quote Link to comment Share on other sites More sharing options...
step Posted April 12, 2017 Share Posted April 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
rrdwitt Posted April 12, 2017 Author Share Posted April 12, 2017 Thank you again! That was absolutely perfect!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.