Jump to content

Math based on Grad year


wcisme

Recommended Posts

Give this code a shot:

 

var s = Left(Field("Grad Year"));

var year = 0;
var diff = 0;
var plural = "";

if (Int(s) <= 12) {
   year = "20" + s;
   }
else {
   year = "19" + s;
   }

diff = 2012 - year;

plural = (diff > 1) ? "years" : "year";

return (diff > 1) ? "It's been " + (2012 - year) + " " + plural + " since your graduation." : "You have yet to graduate.";

 

If the year is less that '12, it assumes the year is in the 2000's. If it's greater than '12, it assumes the year is 1900's.

Link to comment
Share on other sites

Works like a charm! Thanks so much. 1 more question. The client is requesting the year returned to be spelled out instead of numeric. Could that be added to this code? We have talked about an array, but that seems like the long way to get there. I love clients.
Link to comment
Share on other sites

Works like a charm! Thanks so much. 1 more question. The client is requesting the year returned to be spelled out instead of numeric. Could that be added to this code? We have talked about an array, but that seems like the long way to get there. I love clients.

A search for "JavaScript number to words" on this forum turns up several hits, and the same search in Google turns up even more, including this:

http://www.mail-archive.com/fusionpr.../msg01619.html

 

Personally, I think the first link there is the best, since it's just a pure function without any web browser client code like a lot of JavaScript examples have. You can just copy the entire code from the box there into your JavaScript globals, then you can call the toWords function in any rule.

 

For example, if you add the code from that page to your JavaScript globals, then the last line of step's example could do this:

return (diff > 1) ? "It's been " + toWords(GetYear(Today()) - year) + " " + plural + " since your graduation." : "You have yet to graduate.";

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