Forum Moderators: open

Message Too Old, No Replies

Change age and year every year

         

ron351

10:38 am on May 10, 2009 (gmt 0)

10+ Year Member



I am curious if there is a way that will allow a age and year in a script to change every year without having to edit the lines in a script each year when the date comes and passes.
What I am doing is listing all birthdays in our family tree and it is a countdown to how many days are left before the next birthday.
When the birthday comes and the birthdate passes for that current year the countdown stops.
What would be awsome is if there was a way to add something so that the age would update and the year update automatically so when the birthday for the current year passes it will automatically say 365 days in the countdown and the persons age also change to the next year.

I will paste the html code I have below if it don't show you can see what it looks like on a page I have here:
<snipped>
A working list of dates where you can see expired dates is here:
<snipped>
This is why I am looking for a way to either add to this script or a way to auto update the age of the person and the year after the date passes.

Heres the pasted script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Countdown Dates</title>
<style type="text/css">
<!--
body {
background-color: #003366;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 24px;
font-weight: bold;
color: #000000;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 25px;
font-weight: bold;
}
.style3 {
font-family: Tahoma;
font-size: 18px;
font-weight: bold;
}
.style4 {color: #FF0000}
.style11 {font-family: Tahoma; font-size: 14px; font-weight: bold; }
.style12 {
font-family: Tahoma;
font-size: 14px;
}
.style13 {
font-family: Tahoma;
font-size: 12px;
}
-->
</style>
</head>

<body style="background-color: #606060">
<div align="center">
<table width="700" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#606060">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#808080"><div align="center">
<blockquote><script language="JavaScript">
<!--

var finalDate = "June 25, 2009 11:59 PM EST";

var end = new Date(finalDate);
var endOffset = end.getTime() / 100;

window.onload = function() {
calcTime();
setInterval("calcTime()", 100);
}

function calcTime() {

var now = new Date();
var startOffset = now.getTime() / 100;

var length = Math.floor(endOffset - startOffset);

days = Math.floor(length / 864000);
length = length % 864000;

hours = Math.floor(length / 36000);
length = length % 36000;

minutes = Math.floor(length / 600);
length = length % 600;

seconds = length / 10;

// Add trailing zero for seconds, i.e. 5 becomes 5.0
if (length % 10 == 0) seconds += ".0";

// If the deadline has been passed, set everything to zero
if (endOffset < startOffset) {
days = hours = minutes = seconds = 0;
}

var finalString = days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + "";

getObject("countDown").innerHTML = finalString;
}

function getObject(name) {
var ns4 = (document.layers) ? true : false;
var w3c = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;

if (ns4) return eval('document.' + name);
if (w3c) return document.getElementById(name);
if (ie4) return eval('document.all.' + name);
return false;
}

// -->
</script>

<!--CONTENT-->

<!--TITLE-->
<p><span class="style1">Ron---Age 52---June 26 2009 </span>
<!--END TITLE-->
</p>
<div class="style1" id="countDown" name="countDown">
</blockquote>

<p><b><font face="Tahoma" size="5"></font></b></p>

<!--END CONTENT-->
<p class="style13">&nbsp;</p>
</div></td>
</tr>
</table>
</div>

</body>
</html>

====================================
Basically I would just like to see 2009 change to 2010
and the age 52 turn to 53 after the June 26th date passes.
I totally appreciate any help as I can not seem to find anything like it anywhere on the net.
Maybe it isn't possible.
Ron

[edited by: ron351 at 10:49 am (utc) on May 10, 2009]

[edited by: whoisgregg at 8:49 pm (utc) on May 10, 2009]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] [/edit]

ron351

10:46 am on May 10, 2009 (gmt 0)

10+ Year Member



Forgot to post a url to a working list to show you the expired dates and why I am looking for a way to auto update this. You will see some dates expired.
<snipped>
Ron

[edited by: whoisgregg at 8:49 pm (utc) on May 10, 2009]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] [/edit]

g1smd

10:47 am on May 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to store the date of birth to find the age, and take account of leap years too.

ron351

10:53 am on May 10, 2009 (gmt 0)

10+ Year Member



Are you talking as in a database? If you are then I would be in even worse shape as I am the dumbest in that area.
My guess is that I am probably going to have to manually edit each date and age as the day passes.

g1smd

11:04 am on May 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're storing the month and day somewhere, so you need to also store the year.

I also suspect that your current 'countdown' fails (for up to a year before Feb 29th of a leap year, and only after the previous birthday to the one occurring in the 365 days after Feb 29th in the leap year) before Feb 29th of a leap year, for any birthday in the leap year that is after Feb 28th, and before Feb 28th of the year following the leap year. The count will be one day out for those conditions.

tangor

1:32 pm on May 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't PHP and never had the reason to look at Perl, but I do recall that as far back as Quickbasic date calculation modules were available. One only needed a CSV of the core dates and calculations were performed thereafter.

ron351

12:15 am on May 11, 2009 (gmt 0)

10+ Year Member



Our family luckily don't have a birthdate during the leap year dates. So that is a plus.
I guess I may just have to manually change the year and age because it seems it may be just to hard to do otherwise.
Thought there may of been a easy way to accomplish this.
Thanks anyway for the comments,I appreciate it.
Ron

g1smd

8:10 am on May 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*** Our family luckily don't have a birthdate during the leap year dates. ***

No. I am saying that for a Birthday on March 1st, that on February 28th, it will say "1 day to go" every year, although in a leap year it should say "2 days to go".

I guess it also fails (for up to a year before Feb 29th of a leap year, and only after the previous birthday to the one occurring in the 365 days after Feb 29th in the leap year) before Feb 29th of a leap year, for any birthday in any leap year that is after Feb 28th, and is before Feb 28th of the year following the leap year.