Click to See Complete Forum and Search --> : Special counter


Xerces
08-04-2003, 09:08 AM
I've been trying to create an application/applet that can be given a start date and that counts further on. Let me give an ex.
You would give an date like 29th of july 2003, 18.00 (in the code itself) and when you open the applet four days later, it would say, today we are the third of august ... 3 days and 7 hours and 4 minutes have passed since the start.
I've tried several possibilities but everything fails. I can't get it to work but I do need it :( .
Can anyone help?

Xerces
08-05-2003, 02:42 AM
Anyone? I really really need this :(

Gollum
08-05-2003, 04:18 AM
I don't think there is any easy option on this one unless you can find a script out there that already does what you need.
If not, then you need to do the maths...

var t = new Date(2003,6,29,18); // 29th July 2003 18:00
var now = new Date(); // right now

var dt = (now.getTime() - t.getTime())/60000; // difference in mins

var days = Math.floor(dt / 1440);
dt = dt % 1440;
var hours = Math.floor(dt / 24);
var minutes = Math.round(dt % 24);

alert("It's been " + days + " days, " + hours + " hours and " + minutes + " minutes since the beginning!");

Xerces
08-05-2003, 04:29 AM
thankx

Xerces
08-05-2003, 05:05 AM
Hmz, there is still a small flaw in it. When I run it in my page, I get " it's been 6 days and 42 hours ... since the beginning."
What do you think is the prob?

Xerces
08-05-2003, 05:38 AM
The minutes aren't correct either, sometimes he's more then 30 minutes off.
When I tried it, it should read 6 days 20 hours and 42 minutes, but instead I got 6 days 44 hours and 6 minutes.

Xerces
08-05-2003, 08:32 AM
found it myself, the 24 in the code should be 60. Thanx for the help Gollum.

Gollum
08-05-2003, 09:17 AM
ha ha! Found my deliberate mistake (yeah right ;) ). Well done Xerces