Click to See Complete Forum and Search --> : counter based on date


rezin
12-06-2003, 05:36 PM
hi.

i am trying to make counter (not hit counter, but for something else) based on the amount of days passed since a reference date.

for example, lets say today (dec. 6) is the reference date. the count will start at ZERO today. tomorrow the count will be 10000, the following day the count will be 20000, etc.

so basically i need to set the reference, set the amount of incrementation and perhaps even have a stipulation so it will stop counting once it reaches a certain count (date).

any help is greatly appreciated.

thanks.

Pittimann
12-07-2003, 05:43 AM
Hi!

I somehow wonder, what the stuff is good for, anyway, you can do something like that:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var counterVar=10000;//Value added to zero per day
var maxDays=100;//Number of days until counter stops counting
//Begin variables for start date and time
var startSec=0;
var startMin=0;
var startHour=12;
var startDay=6;
var startMonth=12;
var startYear=2003;
//End variables for start date and time
function counterValue() {
date1 = new Date();
date2 = new Date();
diff = new Date();
date1temp = new Date(startMonth+"/"+startDay+"/"+startYear+" "+startHour+":"+startMin+":"+startSec);
date1.setTime(date1temp.getTime());
date2temp = new Date();
date2.setTime(date2temp.getTime());
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();
days = timediff / (1000 * 60 * 60 * 24);
if (days>=maxDays) days=maxDays;
days = Math.floor(days*counterVar);
return days;
}
//-->
</script>
</head>
<body>
<center>
<script language="JavaScript" type="text/javascript">
<!--
document.write(counterValue());
//-->
</script>
</center>
</body>
</html>

Cheers - Pit