PDA

View Full Version : Count-up from a particular year? Help!


1Lit.com
02-06-2005, 20:54/08:54PM
I've found various scripts (http://www.hotscripts.com/JavaScript/Scripts_and_Programs/Countdowns/) 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:

http://javascript.internet.com/clocks/days-old.html

http://www.javascriptkit.com/script/script2/countup.shtml

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

chrishirst
03-06-2005, 05:11/05:11AM
How about;

<script type="text/javascript">
function countyear(yr){
var today=new Date();
var curr_year=today.getYear();
if (curr_year< 1000)
curr_year+=1900;
document.write("This is the "+addSuffix((curr_year- yr) )+" year of whatever");
}

function addSuffix(number){
var years = number.toString();
var suffix = "th";
last = years.substr(years.length-1,1);
if (last == "1") {
suffix = "st";
}
if (last == "2") {
suffix = "nd";
}
if (last == "3") {
suffix = "rd";
}
return years + suffix;
}
</script>



to call onto the page is

<script type="text/javascript">
countyear(1974);
</script>