wcisme Posted April 10, 2012 Share Posted April 10, 2012 Im stuck. I need to calculate how many years since a person graduated. The data only has the last 2 digits in it. Like '97,'02, etc. I tried several different ways to go about this, no success. Any ideas? Quote Link to comment Share on other sites More sharing options...
step Posted April 10, 2012 Share Posted April 10, 2012 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. Quote Link to comment Share on other sites More sharing options...
wcisme Posted April 12, 2012 Author Share Posted April 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 12, 2012 Share Posted April 12, 2012 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."; Quote Link to comment Share on other sites More sharing options...
wcisme Posted April 12, 2012 Author Share Posted April 12, 2012 Thanks guys! 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.