Forum Moderators: open

Message Too Old, No Replies

Count-up from a particular year? Help!

Show result in years e.g. 51st, 52nd

         

1Lit

12:05 am on Jun 3, 2005 (gmt 0)

10+ Year Member



I've found various scripts [hotscripts.com] which allow you to count-up from a particular date, but they display the result in seconds, hours, minutes, years etc. I'd like to show the result in just years and don't need a bloated script. Would like it to also have "th", "nd" and "st" in the relevant places e.g. "51st".

A couple of scripts that I've found are:

[javascript.internet.com...]

[javascriptkit.com...]

Thanks a million. Spent a while trying to solve the conundrum myself, but my Javascript skills are limited.

jalarie

6:18 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Maybe this will help as a starting point:

function NumberSuffix(What) {
if (isNaN(What)) { return ''; } // non-numeric
var NS_String=String(What);
var NS_Length=NS_String.length;
if (NS_Length == 0) { return ''; } // nothing to do
if (NS_Length > 1) {
var NS_Item=NS_String.substring(NS_Length-2,NS_Length-1);
if (NS_Item == 1) { return 'th'; } // teens
}
var NS_Item=NS_String.substring(NS_Length-1);
if (NS_Item == 1) { return 'st'; } // firST
if (NS_Item == 2) { return 'nd'; } // secoND
if (NS_Item == 3) { return 'rd'; } // thiRD
return 'th'; // all others
}