View Full Version : Odd problem with date/time checking

name _F1
Apr 16th, 2007, 06:59 AM
I am using Javascript to check the current time at intervals, and compare it to time(s) stored on the server (in the form of a Javascript array, ordered from earliest to latest times). I am using the format YYYYMMHHmm due to some problems with using timestamps that I encountered.

For some reason, which I am honestly baffled by, there is something wrong with my checkTimes() function which seems to cause it to do nothing. Firebug says that it is being called when it is supposed to, and when I put alerts at the very beginning of the function, they work, but when the alerts are anywhere later than the first line, nothing happens. No errors are thrown, nothing.

The checkTimes() function is called every 10 seconds from another frame, with a date object passed to it. I also tried retrieving the Date object within the function, with the same (non-existent) result.

<script type="text/javascript">
timestamps = new Array(); //Array is populated with PHP from a MySQL database table
timestamps[0] = 200701010101;
//Set this way as using new Array(x) would create the array with x undefined elements

function formatTime(i) {
if (i<10)
{i = "0" + i}
return String(i);

function checkTimes(date) {
month = formatTime(date.getMonth());
day = formatTime(date.Date());
hour = formatTime(date.getHours());
min = formatTime(date.getMinutes());
time = date.getFullYear()+month+day+hour+min;
while (time > timestamps[0]) {

I was originally going to prototype the Date object to create the formatted time, is that more efficient than doing it within the function?