How to properly end a javascript statement?

Javascript: comparing time of day to a show's start and end time?

  • I need to compare the current time of day to a show's start and end time (I loop thru an array of the day's shows) so I can display the current show that is on the air during different times of day. I have it working in PHP, but in converting to javascript, I am having trouble , as I do not understand comparing the current time with a stored time as a string in the format "13:45:00", for example. Here is some of what I have: <script> <!-- var wed_array=new Array(10); for (i=0; i<5; i++) wed_array[i]=new Array(5); // array for wednesday's shows wed_array[0][0]="1"; //show id wed_array[0][1]="Progressive News Weekly"; //show name wed_array[0][2]="Darryl Smith"; //host name wed_array[0][3]="10:00:00"; //show start time wed_array[0][4]="10:59:59"; //show end time wed_array[1][0]="2"; //show id wed_array[1][1]="Show 2"; //show name wed_array[1][2]="John Brown"; //host name wed_array[1][3]="11:00:00"; //show start time wed_array[1][4]="11:59:59"; //show end time // ... //etc. //--> </script> /* so I have to get the current time when the page is browsed by a person, and loop thru the array until I get a match.. the only issue I have trouble with is the functioning of the IF statement comparing time values. Is this a correct statement? */ //(this is part of a switch statement for the weekday). case 3: // wednesday for (x in wed_array) { if (wed_array[x][3] <= nowtime && wed_array[x][4] > nowtime) { noweventname = wed_array[x][1]; nowhost = wed_array[x][2]; found=1; break; } } break; So to clarify, the IF statement above is not evaluating, and it seems to be the current time and /or the show's time in the array is not being compared correctly.. do I need to convert them to a date format to allow the time to be compared? Thanks !

  • Answer:

    It's much easier to use the Javascript Date object which will do all the stuff you want rather than try to implement your own arrays and operators to do this stuff. Here's a quick overview http://www.web-source.net/web_development/javascript_date.htm the main thing it doesn't mention is that new Date can take a timestamp or date/time in numeric formats, not just work for "now" which is the default with no parameters.

biz_dude... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.