Click to See Complete Forum and Search --> : Help creating script for counting via date/time/etc


VanHammersley
02-23-2003, 04:23 PM
Hello,

Im a newbie on this forum (and somewhat to developing scripts), so hopefully Im not asking a question that's been done before...

Ok, here is my dilema....

Im working on a 'no smoking' website, and I need to create a script to countdown the number of people killed everyday from smoking, starting from the date I put my site live (It will, I guess, use a the users clock as the date/time)

Im using a statistic that says someone dies every 10 seconds. So every 10 seconds, the counter needs to be incremented by 1.

I want to put this number in a variable that will be able to be read to a Flash file....basically loaded into a text/input box.

Ive got the Flash portion of reading a variable working...I just need the script to 'crunch the numbers and output the goods'

Any help in a direction, tutorial, example would be greatly appreciated...

Thanks..

Van Hammersley

VanHammersley
02-23-2003, 04:40 PM
Sweet! Thanks Dave!

I will try that out and see where I land...

VanHammersley

:)

VanHammersley
02-23-2003, 05:13 PM
HeyDave,

Here's what I tried:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

// Set your starting date, and the number of deaths as of that date
var startDate = new Date("02/23/2003");
var startCount = 0;

// Then, you would get the current Date/Time as follows:
var currDate = new Date();

// You could then calculate the number of 10 second intervals between those two dates as follows:
var diffDate = currDate.getTime() - startDate.getTime();
diffDate = Math.floor(diffDate / 1000 / 10);

// Lastly, you would display the current number of deaths as that number added to your starting count
alert(startCount + diffDate);

// End -->

</SCRIPT>
</head>
<body>
Test
</body>
</html>

It incremented ok, but the starting number was something like 3670 or something (?)

Can you see why the num would be coming up?

Also, I want to create a variable for the (starCount + diffDate) to put into a Flash text box. Instead of the alert (), can I just have variable = startCount + diffDate; (?)

Thanks again for any help....

VH


-------------------------------------------------------------------

Originally posted by Dave Clark
You would set your starting date, and the number of deaths as of that date, something like this:

var startDate = new Date("01/01/2003");
var startCount = 34987465;

Then, you would get the current Date/Time as follows:

var currDate = new Date();

You could then calculate the number of 10 second intervals between those two dates as follows:

var diffDate = currDate.getTime() = startDate.getTime();
diffDate = Math.floor(diffDate / 1000 / 10);

Lastly, you would display the current number of deaths as that number added to your starting count:

alert(startCount + diffDate);

and using a 10-second timer, you could re-execute that code to keep your current count, well, current.

Ok? ;)

Dave

pyro
02-23-2003, 05:23 PM
you should set this line:

var startCount = 0;

to equal the current number of deaths, as of your startDate. If you leave it at zero, it will just give you the number of deaths today (or, more correctly, the number of 10 second periods today)

And yes, you can change the alert to variable = startCount + diffDate;

VanHammersley
02-23-2003, 06:56 PM
haha...you are so correct! Many have died...

Thanks for the help!

VH ;)