jalberts1 Posted September 24, 2018 Posted September 24, 2018 I'm making college diplomas. I need a rule that will read a date cell and convert it to a sentence. For example, I need 5/18/2018 to convert to: on the eighteenth day of May, in the year of our Lord, 2018 Any ideas? Thank you, John Quote
Dan Korn Posted September 24, 2018 Posted September 24, 2018 Between FusionPro's DateFromString and FormatDate functions, and generic methods of the JavaScript Date object, you can get the English name of the month (i.e. May) and the four-digit year, for a given date. For instance: var date = DateFromString("5/18/2018"); return "the " + date.getDate() + " day of " + FormatDate(date, "MMM") + " in the year " + date.getFullYear(); The part you're missing is how to spell out the day of the month, not as "18", and also not as "eighteen", but as "eighteenth", which is called an ordinal number. That's really a generic JavaScript question (i.e. it's not specific to FusionPro), so your best bet is to search on the Internet, since hundreds of thousands of people are using JavaScript and have already thought of almost every common usage case like this. A Google search for "JavaScript spell out ordinal numbers" returns a lot of hits, including many from Stack Overflow, which is a Q&A site for programming questions. I found one with an answer that seems to work here: https://stackoverflow.com/questions/20425771/how-to-replace-1-with-first-2-with-second-3-with-third-etc So, combining the code in that answer with what we already had above: var special = ['zeroth','first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth']; var deca = ['twent', 'thirt', 'fort', 'fift', 'sixt', 'sevent', 'eight', 'ninet']; function stringifyNumber(n) { if (n < 20) return special[n]; if (n%10 === 0) return deca[Math.floor(n/10)-2] + 'ieth'; return deca[Math.floor(n/10)-2] + 'y-' + special[n%10]; } var date = DateFromString("5/18/2018"); return "the " + stringifyNumber(date.getDate()) + " day of " + FormatDate(date, "MMM") + " in the year " + date.getFullYear(); You could also put everything but the last two lines into the JavaScript Globals if you want to use it in multiple rules. Quote
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.