Forum Moderators: open
I've spent an hour looking for a javascript to calculate up from a particular year (1947 in the case of Cannes). There are various sites with scripts to calculate the number of days you have been alive etc., but not a single one for the number of years up from a particular year.
I found a script which calculates the number of days from a particular date (below). I was wondering if somebody could possibly convert it to count up from a year.
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
var today = new Date()
var targetDate = new Date("12/12/2001") //use full year
var timeAfterTarget = Math.floor(( today.getTime()
- targetDate.getTime() ) / 86400000)
var msg = "Days up from specified date " + timeAfterTarget + "."
document.write(msg)
//-->
</SCRIPT>
One other thing: is it possible to incorporate this feature [javascript.internet.com] into the resultant year, so that it'll display the correct ending after the year, i.e. 51st, 52nd, 53rd.
Thank you VERY much. This will help me out big time :)
<script language="javascript" type="text/javascript">
var start = 1947;
var now = new Date();
diff = (now.getYear() > 1900 ? now.getYear() : (now.getYear() + 100)) - start;
rx = /[^1]1$/;
if(rx.test(diff)){
diff += "st";
}
else{
rx = /[^1]2$/;
if(rx.test(diff)){
diff += "nd";
}
else{
rx = /[^1]3$/;
if(rx.test(diff)){
diff += "rd";
}
else{
diff += "th";
}
}
}
document.write(diff);
</script>